Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 6 additions & 0 deletions cmd/api-response.go
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,12 @@ func (w *trackingResponseWriter) Write(b []byte) (int, error) {
return w.ResponseWriter.Write(b)
}

func (w *trackingResponseWriter) Flush() {
if f, ok := w.ResponseWriter.(http.Flusher); ok {
f.Flush()
}
}

func (w *trackingResponseWriter) Unwrap() http.ResponseWriter {
return w.ResponseWriter
}
24 changes: 24 additions & 0 deletions cmd/api-response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"testing"

"github.com/klauspost/compress/gzhttp"
xhttp "github.com/minio/minio/internal/http"
)

// Tests object location.
Expand Down Expand Up @@ -159,6 +160,29 @@ func TestTrackingResponseWriter(t *testing.T) {
}
}

func TestTrackingResponseWriterFlush(t *testing.T) {
rw := httptest.NewRecorder()
trw := &trackingResponseWriter{ResponseWriter: rw}

trw.Flush()
if trw.headerWritten {
t.Fatal("Flush() should not set headerWritten")
}

// Simulate the ListenNotificationHandler flow: WriteHeader, Write, Flush
trw.WriteHeader(http.StatusOK)
_, err := trw.Write([]byte("event data"))
if err != nil {
t.Fatalf("Write failed: %v", err)
}

xhttp.Flush(trw)

if !rw.Flushed {
t.Fatalf("xhttp.Flush should have flushed the underlying ResponseRecorder via trackingResponseWriter.Flush()")
}
}

func TestHeadersAlreadyWritten(t *testing.T) {
rw := httptest.NewRecorder()
trw := &trackingResponseWriter{ResponseWriter: rw}
Expand Down