From 6706c9225a8dcb976785bdf2c35eb151d54ac18c Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Tue, 18 Jun 2019 11:13:12 -0600 Subject: Implement templates handler; various minor cleanups and bug fixes --- modules/caddyhttp/routes.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'modules/caddyhttp/routes.go') 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) -- cgit v1.2.3