mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-27 22:23:48 +03:00
http: Always set status code via response recorder
Fixes panic if no upstream handler wrote anything to the response
This commit is contained in:
parent
21f1f95e7b
commit
8bae8f5f5a
1 changed files with 5 additions and 0 deletions
|
@ -225,6 +225,11 @@ func (rr *responseRecorder) WriteResponse() error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
CopyHeader(rr.ResponseWriterWrapper.Header(), rr.header)
|
CopyHeader(rr.ResponseWriterWrapper.Header(), rr.header)
|
||||||
|
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.ResponseWriterWrapper.WriteHeader(rr.statusCode)
|
rr.ResponseWriterWrapper.WriteHeader(rr.statusCode)
|
||||||
_, err := io.Copy(rr.ResponseWriterWrapper, rr.buf)
|
_, err := io.Copy(rr.ResponseWriterWrapper, rr.buf)
|
||||||
return err
|
return err
|
||||||
|
|
Loading…
Reference in a new issue