From db4c5e0eaa0b915316e674515d8fffa3ae7dd78b Mon Sep 17 00:00:00 2001 From: Yicheng Qin Date: Thu, 29 May 2014 14:18:50 -0700 Subject: [PATCH] fix(server/v2): set correct content-type for etcdError response "net/http".Error reset the content type, so we get rid of it and write our own one. --- error/error.go | 3 ++- server/v2/tests/get_handler_test.go | 3 +++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/error/error.go b/error/error.go index 4a12ca3b2..67551e4ee 100644 --- a/error/error.go +++ b/error/error.go @@ -143,5 +143,6 @@ func (e Error) Write(w http.ResponseWriter) { status = http.StatusInternalServerError } } - http.Error(w, e.toJsonString(), status) + w.WriteHeader(status) + fmt.Fprintln(w, e.toJsonString()) } diff --git a/server/v2/tests/get_handler_test.go b/server/v2/tests/get_handler_test.go index 8c5f2bd0e..23a582245 100644 --- a/server/v2/tests/get_handler_test.go +++ b/server/v2/tests/get_handler_test.go @@ -24,12 +24,15 @@ func TestV2GetKey(t *testing.T) { v.Set("value", "XXX") fullURL := fmt.Sprintf("%s%s", s.URL(), "/v2/keys/foo/bar") resp, _ := tests.Get(fullURL) + assert.Equal(t, resp.Header.Get("Content-Type"), "application/json") assert.Equal(t, resp.StatusCode, http.StatusNotFound) resp, _ = tests.PutForm(fullURL, v) + assert.Equal(t, resp.Header.Get("Content-Type"), "application/json") tests.ReadBody(resp) resp, _ = tests.Get(fullURL) + assert.Equal(t, resp.Header.Get("Content-Type"), "application/json") assert.Equal(t, resp.StatusCode, http.StatusOK) body := tests.ReadBodyJSON(resp) assert.Equal(t, body["action"], "get", "")