-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Closed
Labels
Description
by tyson@stovepipestudios.com:
http.Header.Add() changes the case of the given header key, which causes problems. See: http://play.golang.org/p/ci5_qeAYRh I'm on MacOS X 10.8.2 using Go 1.0.3, but this issue applies to all platforms and current versions of Go. I understand that this was done intentionally. The comment above the http.Request.Header declaration says: // HTTP defines that header names are case-insensitive. // The request parser implements this by canonicalizing the // name, making the first character and any characters // following a hyphen uppercase and the rest lowercase. It's likely referring to section 3.4.7 of RFC 822, which says: When matching any other syntactic unit, case is to be ignored. For example, the field-names "From", "FROM", "from", and even "FroM" are semantically equal and should all be treated ident- ically. When generating these units, any mix of upper and lower case alphabetic characters may be used. The case shown in this specification is suggested for message-creating processes. In an ideal world, all servers / remote APIs would respect this guideline when parsing and handling HTTP headers. However, they don't, which can cause grief for users of the http package. I spent a fair amount of time myself trying to figure out why a particular API endpoint wasn't finding and accepting my authentication header. It's for this reason that I believe that http.Header.Add() should not change header key casing *because* the RFC says that casing isn't important. If casing isn't important, there's no reason to change it, anyways, and users can ensure that their headers will be handled properly in cases when the remote service doesn't respect the guideline.