Content-Type set in util::handle is overwritten by net/http/server.go
Closed this issue · 1 comments
sebastien-guay commented
Content-Type set in util::handleErr() is overwritten by function Error() in net/http/server.go
Line 105 in 7e8989a
Here is the code in server.go caussing the problem:
func Error(w ResponseWriter, error string, code int) {
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
w.Header().Set("X-Content-Type-Options", "nosniff")
w.WriteHeader(code)
fmt.Fprintln(w, error)
}
What I was doing in util::handleErr() was to not call http.Error(). I was doing this:
w.Header().Set("Content-Type", string(mime))
w.WriteHeader(code)
w.Header().Set("X-Content-Type-Options", "nosniff")
fmt.Fprintln(w, msg)
dhubler commented
fixed. I assume the order of the Header().Set doesn't matter.