-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTTP::Headers gets downcase #8060
Comments
This is due to recent optimizations in #8002. It only affects common header names which are cached downcased for easier comparability (see https://github.com/crystal-lang/crystal/pull/8002/files#diff-520d933e69a34d18025788f47787c6f2R173). Maybe we should consider a different solution to caching common names (for example Because header names are case-insensitive this is not a very serious issue, though. But it can still be annoying. |
We are doing a lot of HTTP::Headers manipulation, and we digest and parse them raw. |
But upcase shouldn't work here because you'd get CONTENT-TYPE instead of Content-Type? In any case, I'll "fix" this by making it always return "Content-Type", "User-Agent", etc. Headers are case insensitive and that's a good default, I think. |
@asterite I meant Capitalize :) my mistake. |
Headers in HTTP/2 are now always transmitted lowercase (followed in HTTP/3) and it's becoming common to now receive headers lowercased, even in HTTP/1 and it's clunky case-insensitiveness (with an HTTP/2 reverse proxy for example, which is now default in Google GKE for example). I strongly advise to join the bandwagon. HTTP headers are now lowercase by default, and that's good. @asterite there is nothing to fix, in fact all headers should always be lowercased. |
@bararchy That doesn't work for
Who says that? Since case doesn't matter, IMHO the best behaviour is to not alter any names. I could accept a general doctrine to consider all header names downcased though, if that's a future proof path. As long as we consequently downcase them everywhere ( |
I'm good as long as what goes in == what comes out, otherwise, there are suprises |
@bararchy Well, that's the question here: Should we keep everything as it comes in (which would imply possibly mixed styles in one place), or should we apply some kind of normalization to headers in order to have uniform representation. |
oops |
Source for the lowercasing headers: https://tools.ietf.org/html/rfc7540#section-8.1.2
|
Yeah for HTTP/2. There is no such rule for older protocols. But I guess we essentially want to use the same data structures for any HTTP protocol, so it's probably better to normalize downcased right away. |
Maybe I can remove the optimization and leave the code as it was before. |
A conservative change including optimization would be to compare common names case-sensitive and use capitalized strings (or both capitalized and downcased). That's strictly better than just reverting the optimization. Alternatively we could just proceed forward and downcase everything as @ysbaddaden suggested. |
@straight-shoota You mean making the lookup hash be: COMMON_HEADERS = {
"content-length" => "content-length",
"Content-Length" => "Content-Length",
# etc.
} ? |
Yes. But you wouldn't need a hash then, a list would suffice when there is no normalization. |
Makes sense. I like that approach. It wouldn't cover other cases like "Content-length", though we might also want to consider that... I'll later update this PR with all these variants. It's probably the best of all worlds: optimized and keeps the original casing in most common cases. Great idea! |
This shows it perfectly:
The expected result is to get back the same "case" for the headers, but instead it gets downcased
The text was updated successfully, but these errors were encountered: