caddyhttp: Write header if needed in responseRecorder.WriteResponse (#6380)

This commit is contained in:
Andreas Kohn 2024-06-07 15:25:36 +02:00 committed by GitHub
parent a10117f8bd
commit 9be4f194e0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 4 deletions

View File

@ -219,13 +219,13 @@ func (rr *responseRecorder) Buffered() bool {
} }
func (rr *responseRecorder) WriteResponse() error { func (rr *responseRecorder) WriteResponse() error {
if rr.stream {
return nil
}
if rr.statusCode == 0 { if rr.statusCode == 0 {
// could happen if no handlers actually wrote anything, // could happen if no handlers actually wrote anything,
// and this prevents a panic; status must be > 0 // 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) rr.ResponseWriterWrapper.WriteHeader(rr.statusCode)
_, err := io.Copy(rr.ResponseWriterWrapper, rr.buf) _, err := io.Copy(rr.ResponseWriterWrapper, rr.buf)