Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

http connect tunnel support #181

Open
chlxt opened this issue Sep 5, 2020 · 0 comments
Open

http connect tunnel support #181

chlxt opened this issue Sep 5, 2020 · 0 comments

Comments

@chlxt
Copy link

chlxt commented Sep 5, 2020

Currently tiny-http may not support CONNECT method well. After the first CONNECT event occurs, all subsequent DATA from peer host should not be treated as Request anymore, so tiny-http should expose corresponding socket(or reader/writer) to the user and remove this connection from contentiously receiving loop thread.

two options I've thought:

  1. changing the interface: incoming_requests() returns new Message type:

    enum Message {
        Error(IoError),
        NewRequest(Request),
    }

    to

    enum Message {
        Error(IoError),
        NewRequest(Request),
        NewData(Vec<u8>),
    }

    and in receiving loop check the message type first, if is CONNECT then keeps track of this connection and doesn't do anymore Reqeust parsing on any subsequent packets.

    let mut is_normal_req = false;
    for rq in client {
        if is_normal_req {
            if(rq.method() == Method::CONNECT) {
                is_normal_req = false;
            }
            todo!(); // push `rq` to queue `messages`
        } else {
            todo!(); // directly return DATA(Vec<u8>)
        }
    }
    
  2. changing the CONNECT related data, when CONNECT arrives, returns CONNECT Request with the underlying sock(or reader/writer) to users, and break the receiving loop thread.

    for rq in client {
        let is_normal_req = rq.method == Method::CONNECT;
        todo!(); // push `rq` to queue `messages`, and attach sock(or reader/writer) to this Reqeust Message if is `CONNECT`
        if is_normal_req {
            break;
        }
    }
    

    now users can reuse returned sock(or reader/writer) to construct new TCP tunnel.

any suggestions?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant