diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2020-01-08 18:37:41 -0700 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2020-01-08 18:37:41 -0700 |
commit | 8bae8f5f5a4e8dd7bf805093b320aadb752432d2 (patch) | |
tree | 507856bd608ba70b5cc905e21d047dee0c6c3da7 /modules/caddyhttp | |
parent | 21f1f95e7b4d37786c34eff8965a284340c2164a (diff) |
http: Always set status code via response recorder
Fixes panic if no upstream handler wrote anything to the response
Diffstat (limited to 'modules/caddyhttp')
-rw-r--r-- | modules/caddyhttp/responsewriter.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/modules/caddyhttp/responsewriter.go b/modules/caddyhttp/responsewriter.go index dd16ce7..a4ea1db 100644 --- a/modules/caddyhttp/responsewriter.go +++ b/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 |