Merge pull request #814 from unihorn/91

fix(server/v2): set correct content-type for etcdError response
This commit is contained in:
Yicheng Qin 2014-06-02 10:38:36 -07:00
commit d5bfca9465
2 changed files with 5 additions and 1 deletions

View File

@ -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())
}

View File

@ -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", "")