Http protocol says headers are case-insensitive, but we treat them case-sensitive
gingters opened this issue · 1 comments
Noticed when accessing ClientRequest.HttpHeaders.TryGetValue()
. When the header name requested is not exactly cased as received, it won't find the value.
HTTP Spec says, header names must be treated case-insensitive (unless HTTP/2, here they need be all-lowercase).
Ref: https://www.rfc-editor.org/rfc/rfc9110.html#fields :
| Fields are sent and received within the header and trailer sections of messages
| Field names are case-insensitive
In a demo environment with a Caddy proxy (for Auto-HTTPS), Caddy uses a library that "normalizes" header naming and changes its casing (making the first letter uppercase, which is fine by http spec), so we need to be able to work with unexpected casings.
I would fix this by finding all creations of HttpHeaders dictionaries for ClientRequest and TargetResponse HttpHeaders properties and use the Dictionary overload with StringComparison.OrdinalIgnoreCase
as the key comparer. This will make it possible to retrieve a header value by a name that doesn't exactly match the received (or sent) casing.