etcdhttp: 415 when content-type not JSON

This commit is contained in:
Brian Waldon 2014-10-28 10:35:15 -07:00
parent d1fb732e63
commit c07b9ae32e
2 changed files with 3 additions and 2 deletions

View File

@ -172,7 +172,7 @@ func (h *adminMembersHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
case "POST": case "POST":
ctype := r.Header.Get("Content-Type") ctype := r.Header.Get("Content-Type")
if ctype != "application/json" { if ctype != "application/json" {
writeError(w, httptypes.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("Bad Content-Type %s, accept application/json", ctype))) writeError(w, httptypes.NewHTTPError(http.StatusUnsupportedMediaType, fmt.Sprintf("Bad Content-Type %s, accept application/json", ctype)))
return return
} }
b, err := ioutil.ReadAll(r.Body) b, err := ioutil.ReadAll(r.Body)

View File

@ -717,6 +717,7 @@ func TestServeAdminMembersFail(t *testing.T) {
URL: mustNewURL(t, adminMembersPrefix), URL: mustNewURL(t, adminMembersPrefix),
Method: "POST", Method: "POST",
Body: ioutil.NopCloser(strings.NewReader("bad json")), Body: ioutil.NopCloser(strings.NewReader("bad json")),
Header: map[string][]string{"Content-Type": []string{"application/json"}},
}, },
&resServer{}, &resServer{},
@ -732,7 +733,7 @@ func TestServeAdminMembersFail(t *testing.T) {
}, },
&errServer{}, &errServer{},
http.StatusBadRequest, http.StatusUnsupportedMediaType,
}, },
{ {
// bad url // bad url