diff --git a/http/handler.go b/http/handler.go index 8cc059035..3226eee50 100644 --- a/http/handler.go +++ b/http/handler.go @@ -964,10 +964,12 @@ func (h *Handler) readURLQueryRequest(r *http.Request) (*pilosa.QueryRequest, er } // writeQueryResponse writes the response from the executor to w. -func (h *Handler) writeQueryResponse(w io.Writer, r *http.Request, resp *pilosa.QueryResponse) error { +func (h *Handler) writeQueryResponse(w http.ResponseWriter, r *http.Request, resp *pilosa.QueryResponse) error { if !validHeaderAcceptJSON(r.Header) { + w.Header().Set("Content-Type", "application/protobuf") return h.writeProtobufQueryResponse(w, resp) } + w.Header().Set("Content-Type", "application/json") return h.writeJSONQueryResponse(w, resp) } diff --git a/server/handler_test.go b/server/handler_test.go index ed7a2bed6..f45aa2422 100644 --- a/server/handler_test.go +++ b/server/handler_test.go @@ -248,6 +248,8 @@ func TestHandler_Endpoints(t *testing.T) { t.Fatalf("unexpected status code: %d", w.Code) } else if body := w.Body.String(); body != `{"results":[2]}`+"\n" { t.Fatalf("unexpected body: %q", body) + } else if w.Header().Get("Content-Type") != "application/json" { + t.Fatalf("unexpected header: %q", w.Header().Get("Content-Type")) } }) @@ -286,6 +288,8 @@ func TestHandler_Endpoints(t *testing.T) { t.Fatal(err) } else if rt, ok := resp.Results[0].(uint64); !ok || rt != 3 { t.Fatalf("unexpected response type: %#v", resp.Results[0]) + } else if w.Header().Get("Content-Type") != "application/protobuf" { + t.Fatalf("unexpected header: %q", w.Header().Get("Content-Type")) } })