fix header casing for Twisted WebSockets #26
Merged
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.
Motivation
While implementing a service that uses WebSockets, I realized we were not keeping header casing with WebSockets served over Twisted, but we would in ASGI.
This was due to a workaround with the saved
rolo.headersthat is not executed in this code path while creating theWebSocketRequest.I've ported the fix over there, and it's exactly the same code that is living in
wsgi.py. However, there isn't really a place for those kind of... utils? So for now it is duplicated.While testing the fix, I realized it was actually fixing the issue in my code served over LocalStack, but was still failing in the unit tests.
This is because the test was served over a simple
Site, when you are supposed to serve it over aWsgiGateway, which contains some logic to preserve header casing. In order to not complicate the unit tests by requiring everything to be a rolo Gateway, I've applied the fix for the WebSocketsSitefixture by adding thesite.protocol = HeaderPreservingHTTPChannel.protocol_factorylike we would in thetwisted.WsgiGateway.Changes
serve_twisted_websocket_listenerto be closer to how Twisted should actually be used (with the Gateway)Request