Skip to content
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

net/http: document that Header.Set canonicalizes the header key #27923

Closed
githubsands opened this issue Sep 28, 2018 · 6 comments
Closed

net/http: document that Header.Set canonicalizes the header key #27923

githubsands opened this issue Sep 28, 2018 · 6 comments
Labels
Documentation FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@githubsands
Copy link

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

1.10.3

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

darwin, amd64

What did you do?

https://play.golang.org/p/l-3GJBY-vWA

What did you expect to see?

Expected key to be the same string HeyHey when adding it to the http header rather then Heyhey.

What did you see instead?

Saw that after adding or setting a string to a header it does not keep the n+1 capital letter causing a check for the same key to fail.

@githubsands githubsands changed the title http.Header.Set fails to keep same string format for its keys. http.Header.Set() fails to keep same string format for its keys. Sep 28, 2018
@ghost
Copy link

ghost commented Sep 28, 2018

Go normalizes header names (see net/http#CanonicalHeaderKey). Why does this matter though? HTTP header names are case-insensitive.

@katiehockman katiehockman changed the title http.Header.Set() fails to keep same string format for its keys. net/http: http.Header.Set() fails to keep same string format for its keys. Sep 28, 2018
@katiehockman katiehockman added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 28, 2018
@katiehockman
Copy link
Contributor

/cc @bradfitz

@bradfitz
Copy link
Contributor

We can document this more but we can't (and shouldn't) change it.

Also it shouldn't matter, as @bontibon pointed out. (In HTTP/2 headers can't even have case.)

If you really need to talk to a broken HTTP/1 server that distinguish cases, you can set the map value directly without using the accessor methods.

@bradfitz bradfitz added help wanted NeedsFix The path to resolution is known, but the work has not been done. labels Sep 28, 2018
@bradfitz bradfitz added this to the Go1.12 milestone Sep 28, 2018
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 28, 2018
@bradfitz bradfitz changed the title net/http: http.Header.Set() fails to keep same string format for its keys. net/http: document that Header.Set canonicalizes the header key Sep 28, 2018
@githubsands
Copy link
Author

githubsands commented Sep 28, 2018

Ah I see "-" between capital letters is a common http header convention.

@bradfitz
Copy link
Contributor

The hyphens are required for many HTTP/HTTP-using RFCs, but the case is not required. It's just a convention.

@gopherbot
Copy link

Change https://golang.org/cl/138677 mentions this issue: net/http: document Header.Set canonicalizes the header key

@golang golang locked and limited conversation to collaborators Oct 2, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge help wanted NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

4 participants