Skip to content

Commit

Permalink
We need to flush the end of the body when retry is streamed
Browse files Browse the repository at this point in the history
  • Loading branch information
juliens authored and traefiker committed Jan 2, 2018
1 parent 23c1a9c commit 3e13ebe
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions middlewares/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ func (retry *Retry) ServeHTTP(rw http.ResponseWriter, r *http.Request) {
// It's a stream request and the body gets already sent to the client.
// Therefore we should not send the response a second time.
if recorder.streamingResponseStarted {
recorder.Flush()
break
}

Expand Down
18 changes: 18 additions & 0 deletions middlewares/retry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,21 @@ type countingRetryListener struct {
func (l *countingRetryListener) Retried(req *http.Request, attempt int) {
l.timesCalled++
}

func TestRetryWithFlush(t *testing.T) {
next := http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
rw.WriteHeader(200)
rw.Write([]byte("FULL "))
rw.(http.Flusher).Flush()
rw.Write([]byte("DATA"))
})

retry := NewRetry(1, next, &countingRetryListener{})
responseRecorder := httptest.NewRecorder()

retry.ServeHTTP(responseRecorder, &http.Request{})

if responseRecorder.Body.String() != "FULL DATA" {
t.Errorf("Wrong body %q want %q", responseRecorder.Body.String(), "FULL DATA")
}
}

0 comments on commit 3e13ebe

Please sign in to comment.