Browse Source
http: Always set status code via response recorder
Fixes panic if no upstream handler wrote anything to the response
master
Matthew Holt
5 years ago
No known key found for this signature in database
GPG Key ID: 2A349DD577D586A5
1 changed files with
5 additions and
0 deletions
-
modules/caddyhttp/responsewriter.go
|
|
@ -225,6 +225,11 @@ func (rr *responseRecorder) WriteResponse() error { |
|
|
|
return nil |
|
|
|
} |
|
|
|
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) |
|
|
|
_, err := io.Copy(rr.ResponseWriterWrapper, rr.buf) |
|
|
|
return err |
|
|
|