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

flush operation will overwrite the origin status code #1460

Merged
merged 2 commits into from
Aug 7, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
flush operation will overwrite the origin status code
  • Loading branch information
congcongke committed Aug 7, 2018
commit 4a6eea71b7cbe6d01d915708a2886a31b2ce81d0
1 change: 1 addition & 0 deletions response_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,5 +110,6 @@ func (w *responseWriter) CloseNotify() <-chan bool {

// Flush implements the http.Flush interface.
func (w *responseWriter) Flush() {
w.WriteHeaderNow()
w.ResponseWriter.(http.Flusher).Flush()
}
16 changes: 16 additions & 0 deletions response_writer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,3 +113,19 @@ func TestResponseWriterHijack(t *testing.T) {

w.Flush()
}

func TestResponseWriterFlush(t *testing.T) {
testServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
writer := &responseWriter{}
writer.reset(w)

writer.WriteHeader(http.StatusInternalServerError)
writer.Flush()
}))
defer testServer.Close()

// should return 500
resp, err := http.Get(testServer.URL)
assert.NoError(t, err)
assert.Equal(t, http.StatusInternalServerError, resp.StatusCode)
}