diff --git a/tsweb/jsonhandler.go b/tsweb/jsonhandler.go index 1093e222a..d249b9b14 100644 --- a/tsweb/jsonhandler.go +++ b/tsweb/jsonhandler.go @@ -32,8 +32,8 @@ func responseError(e string) *response { func writeResponse(w http.ResponseWriter, s int, resp *response) { b, _ := json.Marshal(resp) - w.WriteHeader(s) w.Header().Set("Content-Type", "application/json") + w.WriteHeader(s) w.Write(b) } diff --git a/tsweb/jsonhandler_test.go b/tsweb/jsonhandler_test.go index 990d1f2f2..91d7d1227 100644 --- a/tsweb/jsonhandler_test.go +++ b/tsweb/jsonhandler_test.go @@ -44,6 +44,10 @@ func TestNewJSONHandler(t *testing.T) { t.Fatalf("wrong status: %s %s", d.Status, status) } + if w.Header().Get("Content-Type") != "application/json" { + t.Fatalf("wrong content type: %s", w.Header().Get("Content-Type")) + } + return d }