From 43685e03d929fd589ddea13391d0446c5ee27ce3 Mon Sep 17 00:00:00 2001 From: Alex Vanin Date: Mon, 20 Mar 2023 11:17:31 +0300 Subject: [PATCH] [#60] Implement flusher on all http.ResponseWriters Signed-off-by: Alex Vanin --- api/metrics.go | 6 ++++++ api/router.go | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/api/metrics.go b/api/metrics.go index eaa0c15c0..eb629120c 100644 --- a/api/metrics.go +++ b/api/metrics.go @@ -286,6 +286,12 @@ func (w *responseWrapper) Flush() { } } +func (w *writeCounter) Flush() { + if f, ok := w.ResponseWriter.(http.Flusher); ok { + f.Flush() + } +} + func (w *writeCounter) Write(p []byte) (int, error) { n, err := w.ResponseWriter.Write(p) atomic.AddUint64(&w.countBytes, uint64(n)) diff --git a/api/router.go b/api/router.go index a7fd2a4bc..66f4a0bc8 100644 --- a/api/router.go +++ b/api/router.go @@ -117,6 +117,12 @@ func (lrw *logResponseWriter) WriteHeader(code int) { }) } +func (lrw *logResponseWriter) Flush() { + if f, ok := lrw.ResponseWriter.(http.Flusher); ok { + f.Flush() + } +} + func setRequestID(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // generate random UUIDv4