Merge pull request #34 from pinginfo/fix-api-listenbucketnotification

fix: implement Flush on trackingResponseWriter
This commit is contained in:
Feng Ruohang
2026-07-29 14:48:23 +08:00
committed by GitHub
2 changed files with 30 additions and 0 deletions
+6
View File
@@ -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
View File
@@ -24,6 +24,7 @@ import (
"testing"
"github.com/klauspost/compress/gzhttp"
xhttp "github.com/minio/minio/internal/http"
)
// Tests object location.
@@ -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}