Add support for server-side websocket upgrade #500
  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.
  
    
  
    
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.