From 23a88f8df0ccd37ea84ca3ff36f0faf9edbfc9a2 Mon Sep 17 00:00:00 2001 From: Scott Fleckenstein Date: Fri, 20 Nov 2015 08:29:27 -0800 Subject: [PATCH] Add `flushWriter` to `mutil.WrapWriter()` This allows httptest.ResponseRecorder to be wrapped and still maintain its Flusher compatibility --- web/mutil/writer_proxy.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/web/mutil/writer_proxy.go b/web/mutil/writer_proxy.go index d572812..9f6d776 100644 --- a/web/mutil/writer_proxy.go +++ b/web/mutil/writer_proxy.go @@ -39,6 +39,9 @@ func WrapWriter(w http.ResponseWriter) WriterProxy { if cn && fl && hj && rf { return &fancyWriter{bw} } + if fl { + return &flushWriter{bw} + } return &bw } @@ -123,3 +126,14 @@ var _ http.CloseNotifier = &fancyWriter{} var _ http.Flusher = &fancyWriter{} var _ http.Hijacker = &fancyWriter{} var _ io.ReaderFrom = &fancyWriter{} + +type flushWriter struct { + basicWriter +} + +func (f *flushWriter) Flush() { + fl := f.basicWriter.ResponseWriter.(http.Flusher) + fl.Flush() +} + +var _ http.Flusher = &flushWriter{}