From 9be4f194e036dddd4704a851fd15a9682d9e813d Mon Sep 17 00:00:00 2001 From: Andreas Kohn Date: Fri, 7 Jun 2024 15:25:36 +0200 Subject: [PATCH] caddyhttp: Write header if needed in responseRecorder.WriteResponse (#6380) --- modules/caddyhttp/responsewriter.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/caddyhttp/responsewriter.go b/modules/caddyhttp/responsewriter.go index d51d37cb..808d2de3 100644 --- a/modules/caddyhttp/responsewriter.go +++ b/modules/caddyhttp/responsewriter.go @@ -219,13 +219,13 @@ func (rr *responseRecorder) Buffered() bool { } func (rr *responseRecorder) WriteResponse() error { - if rr.stream { - return nil - } if rr.statusCode == 0 { // could happen if no handlers actually wrote anything, // and this prevents a panic; status must be > 0 - rr.statusCode = http.StatusOK + rr.WriteHeader(http.StatusOK) + } + if rr.stream { + return nil } rr.ResponseWriterWrapper.WriteHeader(rr.statusCode) _, err := io.Copy(rr.ResponseWriterWrapper, rr.buf)