Skip to content

Commit

Permalink
v2: use 'application/json' content-type for error responses (#1353)
Browse files Browse the repository at this point in the history
  • Loading branch information
roncohen committed Sep 4, 2018
1 parent bcbd5a6 commit 77989a5
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion beater/v2_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (v *v2Handler) sendResponse(logger *logp.Logger, w http.ResponseWriter, sr
// but also signals to http.Server that it should close it:
// https://golang.org/src/net/http/server.go#L1254
w.Header().Add("Connection", "Close")

w.Header().Add("Content-Type", "application/json")
buf, err := json.Marshal(sr)
if err != nil {
logger.Errorw("error sending response", "error", err)
Expand Down
3 changes: 3 additions & 0 deletions beater/v2_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,10 @@ func TestRequestIntegration(t *testing.T) {
assert.Equal(t, test.code, w.Code, w.Body.String())
if test.code == http.StatusAccepted {
assert.Equal(t, 0, w.Body.Len())
assert.Equal(t, w.HeaderMap.Get("Content-Type"), "")
} else {
assert.Equal(t, w.HeaderMap.Get("Content-Type"), "application/json")

body := w.Body.Bytes()
tests.AssertApproveResult(t, "approved-stream-result/TestRequestIntegration"+test.name, body)
}
Expand Down

0 comments on commit 77989a5

Please sign in to comment.