-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Prevent Request headers canonicalization #607
Conversation
Hi Erik, I reviewed the PR. I’m lucky to have control over the client, so for certain scenarios, I can pass metadata directly and didn’t have to implement it the way you did. That said, the PR looks good overall. It does consume more RAM since you're cloning data. For the tests, you might consider adding some new elements, for instance, from here: Additionally, instead of parsing as you’ve done, why not leverage customize the original package that also have more integrity checks? This way, you’d avoid cloning everything and could simply rely on Go's implementation from the source. If some functions is private I think you can expose it instead of copy/paste by abusing linkname like already done here: Let me know what you think! |
Thanks for the review, I really appreciate that. I'm a bit skeptical about the abuse of linkname, for a library like that which is used by different versions of the Go compiler, which can break itself if the standard library changes the signature. |
a53387b
to
ed3a6e1
Compare
9b495a8
to
3df826e
Compare
Updates:
If someone wants to add anything else to the review, I'm happy to evaluate new changes. However, next week I will merge this Pull Request. |
3df826e
to
f18e376
Compare
LGTM! |
Fixes #559.
Thanks to a suggestion made by @alessiodallapiazza, I found this thread where they talk about the request canonicalization problem: golang/go#37834.
Basically, if the request specifies an header value, the Go http parser can rewrite its name to make it compliant with the RFC standard, but this behavior will break some requests made to websites that expects a different case (e.g. everything lowercase) for the name.
In this PR I tried to implement a (not too ugly) solution for this problem.
I still rely on the standard Go implementation, which handles all the edge cases, but I duplicate the data stream to parse manually only a list of the header names by ourselves.
To extract headers I used a simplified version of https://github.com/evanphx/wildcat, modified by me.
Then, for each header, I manually replace the name saved inside the
Headers
map only if it's different than the canonicalized one.I added some additional tests for everything.
Does someone want to review this? Is there some missing edge case?