diff --git a/caddyhttp/header/header.go b/caddyhttp/header/header.go index 7207c52e6..28f95d45f 100644 --- a/caddyhttp/header/header.go +++ b/caddyhttp/header/header.go @@ -115,3 +115,23 @@ func (rww *responseWriterWrapper) Hijack() (net.Conn, *bufio.ReadWriter, error) } return nil, nil, httpserver.NonHijackerError{Underlying: rww.w} } + +// Flush implements http.Flusher. It simply wraps the underlying +// ResponseWriter's Flush method if there is one, or panics. +func (rww *responseWriterWrapper) Flush() { + if f, ok := rww.w.(http.Flusher); ok { + f.Flush() + } else { + panic(httpserver.NonFlusherError{Underlying: rww.w}) // should be recovered at the beginning of middleware stack + } +} + +// CloseNotify implements http.CloseNotifier. +// It just inherits the underlying ResponseWriter's CloseNotify method. +// It panics if the underlying ResponseWriter is not a CloseNotifier. +func (rww *responseWriterWrapper) CloseNotify() <-chan bool { + if cn, ok := rww.w.(http.CloseNotifier); ok { + return cn.CloseNotify() + } + panic(httpserver.NonCloseNotifierError{Underlying: rww.w}) +}