Reputation: 526
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.
Upvotes: 14
Views: 10743
Reputation: 120931
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.
Upvotes: 24