From c93e30454ffcdc135a2fe762c0b1509b8c7f7f14 Mon Sep 17 00:00:00 2001 From: WeidiDeng Date: Tue, 12 Mar 2024 04:03:20 +0800 Subject: [PATCH] caddyhttp: suppress flushing if the response is being buffered (#6150) * suppress flushing if the response is being buffered * fix lint --------- Co-authored-by: Matt Holt --- modules/caddyhttp/responsewriter.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/caddyhttp/responsewriter.go b/modules/caddyhttp/responsewriter.go index 37c26463..51f672ee 100644 --- a/modules/caddyhttp/responsewriter.go +++ b/modules/caddyhttp/responsewriter.go @@ -230,6 +230,16 @@ func (rr *responseRecorder) WriteResponse() error { return err } +// FlushError will suppress actual flushing if the response is buffered. See: +// https://github.com/caddyserver/caddy/issues/6144 +func (rr *responseRecorder) FlushError() error { + if rr.stream { + //nolint:bodyclose + return http.NewResponseController(rr.ResponseWriterWrapper).Flush() + } + return nil +} + func (rr *responseRecorder) Hijack() (net.Conn, *bufio.ReadWriter, error) { //nolint:bodyclose conn, brw, err := http.NewResponseController(rr.ResponseWriterWrapper).Hijack()