mirror of
https://github.com/pgsty/minio.git
synced 2026-07-31 15:55:18 +03:00
Merge pull request #34 from pinginfo/fix-api-listenbucketnotification
fix: implement Flush on trackingResponseWriter
This commit is contained in:
@@ -1060,6 +1060,12 @@ func (w *trackingResponseWriter) Write(b []byte) (int, error) {
|
|||||||
return w.ResponseWriter.Write(b)
|
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 {
|
func (w *trackingResponseWriter) Unwrap() http.ResponseWriter {
|
||||||
return w.ResponseWriter
|
return w.ResponseWriter
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/klauspost/compress/gzhttp"
|
"github.com/klauspost/compress/gzhttp"
|
||||||
|
xhttp "github.com/minio/minio/internal/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Tests object location.
|
// 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) {
|
func TestHeadersAlreadyWritten(t *testing.T) {
|
||||||
rw := httptest.NewRecorder()
|
rw := httptest.NewRecorder()
|
||||||
trw := &trackingResponseWriter{ResponseWriter: rw}
|
trw := &trackingResponseWriter{ResponseWriter: rw}
|
||||||
|
|||||||
Reference in New Issue
Block a user