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

Comments

Projects
None yet
5 participants
@githubsands
Copy link

commented Sep 28, 2018

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

@bontibon

This comment has been minimized.

Copy link
Contributor

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

This comment has been minimized.

Copy link
Contributor

commented Sep 28, 2018

/cc @bradfitz

@bradfitz

This comment has been minimized.

Copy link
Member

commented Sep 28, 2018

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 this to the Go1.12 milestone 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

This comment has been minimized.

Copy link
Author

commented Sep 28, 2018

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

@bradfitz

This comment has been minimized.

Copy link
Member

commented Sep 28, 2018

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

@gopherbot

This comment has been minimized.

Copy link

commented Sep 30, 2018

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

@gopherbot gopherbot closed this in 9ec5d9c Oct 2, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.