-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
(fix): Make request.get_headers
fully case insensitive
#54
Conversation
Thank you, but header names must always be lowercased when using I'll do a quick once over of the docs to see if we can make that clearer. |
Only lowercase header names are valid, so this PR would make it less clear what the contract of this package is while doing additional needless work. If we were to accept this we would need to make all operations on headers case insensitive, which would require an opaque type with a smart constructor. This would be a large breaking change and mean pattern matching can no longer be used. I don't think this is a worthwhile trade. |
I don't understand why we would need to make the constructor opaque? Why would operations on the header key require that if we always |
Because that's only one of the countless ways one can interact with headers. If we add that here we force the programmer to themselves lowercase every key they interact with as the contract then states they can be either. This library does not aim to be as close to that document as possible, it instead abstracts over all the HTTP versions in a way that is practical for Gleam. In HTTP1 header keys are case insensitive. In HTTP2 and HTTP3 they have to be lowercase. Gleam doesn't have case insensitive strings and uppercase violates HTTP2/3 while being more verbose for the programmer, so lowercase is the best option. |
Ahhh, TIL. That's the bit I was missing - I haven't had to do much work wrt to http2/http3.
I see what you're saying, and now I see why you would need (want?) an opaque type. That being said, without a major version bump and moving to opaque types/breaking the API I think we're talking about two sides of the same coin.
Is this not already the case? For libraries/code constructing That's why I think something like this is more favorable because it at least buys the ability/opportunity for some certainty/guarantees for the libraries/code consuming Hopefully my tone here is not critical, negative, or aggressive - I very much am asking and discussing in good faith and as always appreciate your time, work, and feedback! |
It's not the case today because it's only adding headers (which is typically done with a string literal or by the web server or client itself) that need to be thought about and done in some precise way, while all work that manipulates headers can depend on the format being lowercase. There's a precise contract for this type so we will not write any code that violates the contract. |
I appreciate your stance and time. I fundamentally disagree but I can understand your stance and why you're sticking to it. I'll close both of these PRs as I don't think I'll persuade you hahah My last thoughts; Gleam's ethos, at least to me, seems to be along the lines of "Be practical, be friendly, do things one way, do things the simple way, and help everyone avoid mistakes". To me, the current contract/api for this type is at odds with that ethos. Asking me as a user to always remember to lowercase headers prior to using the |
The current implementation of
request.get_headers
fails in situation where the Header key(s) is/are not lowercase. If you construct aRequest
object and supply the headers to the constructor directly, the header keys are never lowercased. #53 would add additional api's to help prevent this in most cases by guiding users to use the builder pattern instead.However this PR changes
get_headers
to additionally lowercase each headers key while searching.In addition, I added test coverage for this that validates it failing in
main
and it passing with this pr/change.