diff options
author | Matthew Holt <mholt@users.noreply.github.com> | 2019-06-18 11:13:12 -0600 |
---|---|---|
committer | Matthew Holt <mholt@users.noreply.github.com> | 2019-06-18 11:13:12 -0600 |
commit | 6706c9225a8dcb976785bdf2c35eb151d54ac18c (patch) | |
tree | 1e278a1261e826d0bda3c924bd179aabd0af2e92 /modules/caddyhttp/routes.go | |
parent | 5137859e47678aae81e178ca7d164f9e2b4e3121 (diff) |
Implement templates handler; various minor cleanups and bug fixes
Diffstat (limited to 'modules/caddyhttp/routes.go')
-rw-r--r-- | modules/caddyhttp/routes.go | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/modules/caddyhttp/routes.go b/modules/caddyhttp/routes.go index 596149d..8033b91 100644 --- a/modules/caddyhttp/routes.go +++ b/modules/caddyhttp/routes.go @@ -186,17 +186,21 @@ type middlewareResponseWriter struct { func (mrw middlewareResponseWriter) WriteHeader(statusCode int) { if !mrw.allowWrites { - panic("WriteHeader: middleware cannot write to the response") + // technically, this is not true: middleware can write headers, + // but only after the responder handler has returned; either the + // responder did nothing with the response (sad face), or the + // middleware wrapped the response and deferred the write + panic("WriteHeader: middleware cannot write response headers") } mrw.ResponseWriterWrapper.WriteHeader(statusCode) } func (mrw middlewareResponseWriter) Write(b []byte) (int, error) { if !mrw.allowWrites { - panic("Write: middleware cannot write to the response") + panic("Write: middleware cannot write to the response before responder") } return mrw.ResponseWriterWrapper.Write(b) } // Interface guard -var _ HTTPInterfaces = middlewareResponseWriter{} +var _ HTTPInterfaces = (*middlewareResponseWriter)(nil) |