From c9e40abfb840d76bfef62488ed037b7e75183177 Mon Sep 17 00:00:00 2001 From: Zijie Lu Date: Tue, 14 Jul 2020 15:27:26 -0400 Subject: [PATCH] tsweb: jsonhandler: fix content type Signed-off-by: Zijie Lu --- tsweb/jsonhandler.go | 2 +- tsweb/jsonhandler_test.go | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) 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 }