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.
So, it's looking like
h11
is about to get support for preserving header casing, which is pretty fantastic.Turns out we need to do some work on our side as well in order to take advantage of that, as the test case in this PR demonstrates...
In the test case we're mirroring back whatever headers the transport layer is passed, so that we can check that we're receiving them with the correct casing at that point.
Without this pull request, the headers are all lowercased. After this pull request, the header casing is preserved, although
Headers
is still a case-insensitive dict.In order to support this I've made some internal changes to the
Headers
class, while trying not to otherwise alter the behaviour.We now store header information as a three-tuple of
(raw_key, lowercase_key, value)
.We always compare against and expose
lowercase_key
, so thatHeaders
is always case-insensitive.The only provisos to that are:
headers.raw
interface does expose headers a byte pairs, including the full original casing on the key.I'm aware that we've got a bunch of refinements on
Headers
that we could make, in the same way that we've recently polished up the edges of theURL
interface, but I'd like us to treat those separately to this PR.