@marcel91200 / caddy Mirror · read-only / commits / 8bae8f5f
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

http: Always set status code via response recorder

Fixes panic if no upstream handler wrote anything to the response

Matthew Holt committed Jan 8, 2020 at 18:37 UTC 8bae8f5f5a4e8dd7bf805093b320aadb752432d2
1 file changed +5
modules/caddyhttp/responsewriter.go
+5
@@ -225,6 +225,11 @@ func (rr *responseRecorder) WriteResponse() error {
225 return nil
226 }
227 CopyHeader(rr.ResponseWriterWrapper.Header(), rr.header)
228 + if rr.statusCode == 0 {
229 + // could happen if no handlers actually wrote anything,
230 + // and this prevents a panic; status must be > 0
231 + rr.statusCode = http.StatusOK
232 + }
233 rr.ResponseWriterWrapper.WriteHeader(rr.statusCode)
234 _, err := io.Copy(rr.ResponseWriterWrapper, rr.buf)
235 return err