From 852a47fe37e4414581d88a591ccf9282161d08a9 Mon Sep 17 00:00:00 2001 From: Jacques Fuentes Date: Thu, 17 Apr 2014 14:53:07 -0400 Subject: [PATCH] Ensure we write json header before writing bytes In net/http once we've issued a Write() the response is sent over the wire including the header! The tests didn't catch this because I used a net/http/httptest.RequestRecorder which doesn't follow those semantics. --- command/agent/http.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/command/agent/http.go b/command/agent/http.go index 9241ca493..a5fde2dbd 100644 --- a/command/agent/http.go +++ b/command/agent/http.go @@ -124,8 +124,8 @@ func (s *HTTPServer) wrap(handler func(resp http.ResponseWriter, req *http.Reque if err = enc.Encode(obj); err != nil { goto HAS_ERR } - resp.Write(buf.Bytes()) resp.Header().Set("Content-Type", "application/json") + resp.Write(buf.Bytes()) } } return f