Add support for server-side websocket upgrade#500
Add support for server-side websocket upgrade#500quinnj wants to merge 1 commit intoawslabs:mainfrom
Conversation
|
(motivation-wise, this is one of the last pieces of functionality we are hoping to support to have the Julia HTTP.jl package be able to replace it's internal implementation with aws-c-http functionality: JuliaWeb/HTTP.jl#1213) |
|
(also, obviously additional documentation and tests can/would be added depending on how initial reviews of the proposed code go) |
|
Bump @graebm for review/thoughts |
|
Bump @TingDaoK / @DmitriyMusatkin ? |
|
like what we mentioned before, here. The server-side features will not be prioritized by the team. I can try to take a look, but I will also need to read through the spec to have better understanding and to balance between other projects we are planning to work on. |
The main idea here is a new
aws_websocket_upgradefunction that allows creating anaws_websocketinstance from a server-side stream. In order for the stream to correctly be marked as having switched protocols ins_stream_complete, I added ais_switching_protocolsbool field to theaws_h1_encoder_messagestruct that is checked ins_stream_complete.Usage would then allow calling
aws_websocket_upgradefrom the server-sideon_completefunction ofaws_http_request_handler_optionsand using theaws_websocketinstance as desired as a server websocket.I recognize that there may be a cleaner or more desirable way to track the
is_switching_protocols, but after playing around with a few things, this approach seemed pretty simple. If we'd prefer to track this on theaws_h1_streaminstead, or in some other way, I'm open to ideas.I'm also open to other approaches on how to handle/allow the overall
aws_websocket_upgrade. The other thought I had was perhaps you could pass something like the proposedaws_websocket_server_upgrade_optionsto the server configuration options itself and thenaws_websocket_upgradewould be called automatically if an incoming websocket upgrade request was detected? i.e. teh websocket response would automatically be sent, the websocket upgraded, and then twoaws_websocket_on_connectandaws_websocket_on_connect_shutdowncallback functions would be required? That seemed a little more involved and I wasn't sure if it would even work dependency wise with server bringing in websocket definitions.I also realize a discussion/issue could have been opened around this, but I've also just been personally curious to dive in and try something out in the project and this has been a fun way to get to know all the http (h1 at least) lifecycle code. Happy to restart if there are ideas on how to do something like this cleaner/simpler starting from scratch.
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.