From c5d6b22f3748690102835f5c1d4d4a37039df51c Mon Sep 17 00:00:00 2001 From: WeidiDeng Date: Mon, 11 Mar 2024 11:04:35 +0800 Subject: [PATCH] chore: encode: use FlushError instead of Flush (#6168) Co-authored-by: Francis Lavoie --- modules/caddyhttp/encode/encode.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/caddyhttp/encode/encode.go b/modules/caddyhttp/encode/encode.go index e2649031..4bc39000 100644 --- a/modules/caddyhttp/encode/encode.go +++ b/modules/caddyhttp/encode/encode.go @@ -202,15 +202,15 @@ func (enc *Encode) Match(rw *responseWriter) bool { return enc.Matcher.Match(rw.statusCode, rw.Header()) } -// Flush implements http.Flusher. It delays the actual Flush of the underlying ResponseWriterWrapper -// until headers were written. -func (rw *responseWriter) Flush() { +// FlushError is an alternative Flush returning an error. It delays the actual Flush of the underlying +// ResponseWriterWrapper until headers were written. +func (rw *responseWriter) FlushError() error { if !rw.wroteHeader { // flushing the underlying ResponseWriter will write header and status code, // but we need to delay that until we can determine if we must encode and // therefore add the Content-Encoding header; this happens in the first call // to rw.Write (see bug in #4314) - return + return nil } // also flushes the encoder, if any // see: https://github.com/jjiang-stripe/caddy-slow-gzip @@ -221,7 +221,7 @@ func (rw *responseWriter) Flush() { } } //nolint:bodyclose - http.NewResponseController(rw.ResponseWriter).Flush() + return http.NewResponseController(rw.ResponseWriter).Flush() } // Hijack implements http.Hijacker. It will flush status code if set. We don't track actual hijacked