-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Description
Please answer these questions before submitting your issue. Thanks!
What version of Go are you using (go version
)?
1.7
What operating system and processor architecture are you using (go env
)?
ubuntu, amd64
What did you do?
in a http server handler,
first call w.WriteHeader(http.StatusOK)
then call w.Header().Set("Content-Type", "application/json")
then w.Write(somedata compressed by gzip)
What did you expect to see?
The Content-Type in response message captured by troubleshooting tool of chrome/firefox becomes application/x-gzip
What did you see instead?
The Content-Type should be application/json as I set.
On the other hand, if I change the order. call w.Header().Set("Content-Type", "application/json") ahead of the w.WriteHeader(http.StatusOK), the Content-Type keeps what it is. Seems setting status ahead of write content-type trigger the logic to DetectContentType automatically. It's overwrite whatever content-type I set later.
Because of that, gzip content can't be parsed in firefox. Of course, I worked around it by changing the code to set content-type first. But it apparently a trap since there is no doc saying you should always set content-type before set status by WriteHeader.