I am recently using golang library "net/http",while add some header info to request, I found that the header keys are changing, e.g
request, _ := &http.NewRequest("GET", fakeurl, nil)
request.Header.Add("MyKey", "MyValue")
request.Header.Add("MYKEY2", "MyNewValue")
request.Header.Add("DONT-CHANGE-ME","No")
however, when I fetch the http message package, I found the header key changed like this:
Mykey: MyValue
Mykey2: MyNewValue
Dont-Change-Me: No
I using golang 1.3, then how to keep key case sensitive or keep its origin looking? thx.
An HTTP header consists of its case-insensitive name followed by a colon ( : ), then by its value.
CORS Origin is Case Sensitive.
Caching directives are case-insensitive. However, lowercase is recommended because some implementations do not recognize uppercase directives.
It was always just case insensitive but some clients would preserve or enforce a special casing. curl for example typically passes on the casing used by the user - unless for HTTP/2 which is lowercase by spec.
The http.Header Add and Set methods canonicalize the header name when adding values to the header map. You can sneak around the canonicalization by adding values using map operations:
request.Header["MyKey"] = []string{"MyValue"}
request.Header["MYKEY2"] = []string{"MyNewValue"}
request.Header["DONT-CHANGE-ME"] = []string{"No"}
As long as you use canonical names for headers known to the transport, this should work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With