header: Implement Flusher and CloseNotifier

This commit is contained in:
Matthew Holt 2016-11-02 08:13:05 -06:00
parent a2900e46f4
commit 14500d8204

View File

@ -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})
}