Skip to content

Commit 65795ee

Browse files
committed
fix: implement Flush on trackingResponseWriter
Allows the trackingResponseWriter to properly proxy flush requests to the underlying http.Flusher. This ensures compatibility with streaming responses.
1 parent f48dbe7 commit 65795ee

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

cmd/api-response.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1060,6 +1060,12 @@ func (w *trackingResponseWriter) Write(b []byte) (int, error) {
10601060
return w.ResponseWriter.Write(b)
10611061
}
10621062

1063+
func (w *trackingResponseWriter) Flush() {
1064+
if f, ok := w.ResponseWriter.(http.Flusher); ok {
1065+
f.Flush()
1066+
}
1067+
}
1068+
10631069
func (w *trackingResponseWriter) Unwrap() http.ResponseWriter {
10641070
return w.ResponseWriter
10651071
}

cmd/api-response_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424
"testing"
2525

2626
"github.com/klauspost/compress/gzhttp"
27+
xhttp "github.com/minio/minio/internal/http"
2728
)
2829

2930
// Tests object location.
@@ -159,6 +160,29 @@ func TestTrackingResponseWriter(t *testing.T) {
159160
}
160161
}
161162

163+
func TestTrackingResponseWriterFlush(t *testing.T) {
164+
rw := httptest.NewRecorder()
165+
trw := &trackingResponseWriter{ResponseWriter: rw}
166+
167+
trw.Flush()
168+
if trw.headerWritten {
169+
t.Fatal("Flush() should not set headerWritten")
170+
}
171+
172+
// Simulate the ListenNotificationHandler flow: WriteHeader, Write, Flush
173+
trw.WriteHeader(http.StatusOK)
174+
_, err := trw.Write([]byte("event data"))
175+
if err != nil {
176+
t.Fatalf("Write failed: %v", err)
177+
}
178+
179+
xhttp.Flush(trw)
180+
181+
if !rw.Flushed {
182+
t.Fatalf("xhttp.Flush should have flushed the underlying ResponseRecorder via trackingResponseWriter.Flush()")
183+
}
184+
}
185+
162186
func TestHeadersAlreadyWritten(t *testing.T) {
163187
rw := httptest.NewRecorder()
164188
trw := &trackingResponseWriter{ResponseWriter: rw}

0 commit comments

Comments
 (0)