Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@bentsku
Copy link
Contributor

@bentsku bentsku commented Feb 6, 2025

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.headers that is not executed in this code path while creating the WebSocketRequest.

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 a WsgiGateway, 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 WebSockets Site fixture by adding the site.protocol = HeaderPreservingHTTPChannel.protocol_factory like we would in the twisted.WsgiGateway.

Changes

  • update the tests to cover cased headers
  • update the serve_twisted_websocket_listener to be closer to how Twisted should actually be used (with the Gateway)
  • fix the logic by adding the restoration of header casing before creating the SansIO Request

@bentsku bentsku requested a review from thrau February 6, 2025 00:21
@bentsku bentsku self-assigned this Feb 6, 2025
@bentsku bentsku force-pushed the fix-raw-headers-in-ws branch from 07a7d74 to 2928dd3 Compare February 7, 2025 13:58
@bentsku bentsku requested a review from alexrashed February 10, 2025 11:34
Copy link
Member

@alexrashed alexrashed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! Thanks for jumping on this and fixing the header casing in the Websocket implementation! I added some PR comments with some questions I have, once we discussed those we should be good to go! 🚀 🦸🏽

@bentsku bentsku requested a review from alexrashed February 10, 2025 14:38
Copy link
Member

@alexrashed alexrashed left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the detailed explanations on the questions! The changes are looking great! Kudos for proactively jumping on fixing the issue here in rolo! 🦸🏽 💯

@bentsku bentsku merged commit 43d4a87 into main Feb 10, 2025
4 checks passed
@bentsku bentsku deleted the fix-raw-headers-in-ws branch February 10, 2025 16:25
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

Successfully merging this pull request may close these issues.

3 participants