CONNECT method (Proof-of-Concept) #1482
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I've been experimenting with CONNECT to write a proxy server: https://github.com/zuiderkwast/deputy. (Is the name Deputy already taken or reserved for something else in the Cowboy world?) I've tested it only manually by configuring it as a proxy running on localhost in Firefox.
Feel free to pick selected stuff from this PR, now or later. I don't really need it for any serious project.
Changes to Cowboy:
cowboy_httpandcowboy_http2and restrictions forbidding CONNECT removed. Path is set to "/" rather than omitted, to make the request pass throughcowboy_routerandcowboy_handlerunmodified. (It's a hack.)cowboy_tunnelmodelled aftercowboy_websocketis added.cowboy_httpfor taking over the connection process without sending 101 Switching Protocols.The flow, in short:
Handler:initis called. For CONNECT requests, it may return{cowboy_tunnel, ...}.cowboy_tunnel:upgradeis called. It calls cowboy_http with a new command{takeover, ...}which has the same effect as{switch_protocol, ...}, except 101 is not sent. Takover is called in the connection process.cowboy_tunnelcallsHandler:tunnel_initin the connection process. Here, a TCP connection (tunnel) is supposed to be created.cowboy_tunnelsends 200 OK to the client and the tunnel is open.Handler:tunnel_infois called. On data from the client,Handler:tunnel_handleis called.TODO: