Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

console logger HTTP status code bug fixed #3453

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions response_writer.go
Expand Up @@ -61,6 +61,7 @@ func (w *responseWriter) WriteHeader(code int) {
if code > 0 && w.status != code {
if w.Written() {
debugPrint("[WARNING] Headers were already written. Wanted to override status code %d with %d", w.status, code)
return
}
w.status = code
}
Expand Down
18 changes: 18 additions & 0 deletions response_writer_test.go
Expand Up @@ -132,3 +132,21 @@ func TestResponseWriterFlush(t *testing.T) {
assert.NoError(t, err)
assert.Equal(t, http.StatusInternalServerError, resp.StatusCode)
}

func TestResponseWriterStatusCode(t *testing.T) {
testWriter := httptest.NewRecorder()
writer := &responseWriter{}
writer.reset(testWriter)
w := ResponseWriter(writer)

w.WriteHeader(http.StatusOK)
w.WriteHeaderNow()

assert.Equal(t, http.StatusOK, w.Status())
assert.True(t, w.Written())

w.WriteHeader(http.StatusUnauthorized)

// status must be 200 although we tried to change it
assert.Equal(t, http.StatusOK, w.Status())
}