Skip to content

Commit 0a6e2c8

Browse files
author
Robin Diddams
authored
Merge pull request #114 from pinpt/fix-header
WriteHeader is to be called _after_ all headers are set
2 parents 4078a41 + 23d8177 commit 0a6e2c8

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

httpmessage/http.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ type jsonResponse struct {
2020

2121
// RenderStatus will render an appropriate message detail
2222
func RenderStatus(w http.ResponseWriter, req *http.Request, status int, title, msg string) {
23-
w.WriteHeader(status)
2423
w.Header().Set("Cache-Control", "max-age=0,no-cache,no-store")
2524
accept := req.Header.Get("accept")
2625
ct := req.Header.Get("content-type")
2726
rw := req.Header.Get("x-requested-with") == "XMLHttpRequest"
2827
if strings.Contains(accept, "json") || rw || strings.Contains(ct, "json") {
2928
w.Header().Set("Content-Type", "application/json")
29+
w.WriteHeader(status)
3030
w.Write([]byte(pjson.Stringify(jsonResponse{false, msg})))
3131
return
3232
}
@@ -37,5 +37,6 @@ func RenderStatus(w http.ResponseWriter, req *http.Request, status int, title, m
3737
} else {
3838
message = msg
3939
}
40+
w.WriteHeader(status)
4041
tmpl.Execute(w, templateParams{title, message, err})
4142
}

0 commit comments

Comments
 (0)