fix header case handling and support twisted >=24.10 #34
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
In twisted/twisted#12264, the internal API for header case handling was significantly refactored. Rolo was modifying twisted internals to implement a raw header casing mode, which then broke.
This PR creates a backwards compatible change, that will work with twisted
>24(both pre- and post- refactor versions).Discussion
The PR introduces a new
Headersubclass that implements its own case handling. The main motivation for twisted/twisted#12264 was performance of header encoding, an issue we don't have since we don't actually do any encoding of headers in raw header mode.The drawback of this new class is that
HeaderPreservingHTTPChannelandHeaderPreservingWSGIResponseare no longer compatible with the default twisted request object. This actually surfaced because the way the requestFactory was passed was also changed, and until I added it explicitly toserve_twisted_websocket_listener, the tests would fail.Anyway, I think it's OK, since no one really instantiates manually a
Siteobject for serving rolo routers, and for serving Gateway instances we already have the documentedTwistedGateway(Site)which configures the Site object correctly.I also removed the copying of the default
_caseMappings, since it wasn't doing anything. Their values were always overwritten byHeaderPreservingHTTPChannel.headerReceived, andHeaderPreservingWSGIResponse.startResponseanyway.Changes