http.CloseNotifier implementation for http.ResponseWriter wrapper

Signed-off-by: Tw <tw19881113@gmail.com>
This commit is contained in:
Tw 2016-04-11 12:16:41 +08:00
parent 6a7b777f14
commit c64cf218b0
2 changed files with 18 additions and 0 deletions

View File

@ -141,3 +141,12 @@ func (w *gzipResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
}
return nil, nil, fmt.Errorf("not a Hijacker")
}
// CloseNotify implements http.CloseNotifier.
// It just inherits the underlying ResponseWriter's CloseNotify method.
func (w *gzipResponseWriter) CloseNotify() <-chan bool {
if cn, ok := w.ResponseWriter.(http.CloseNotifier); ok {
return cn.CloseNotify()
}
panic("not a CloseNotifier")
}

View File

@ -87,3 +87,12 @@ func (r *ResponseRecorder) Flush() {
panic("not a Flusher") // should be recovered at the beginning of middleware stack
}
}
// CloseNotify implements http.CloseNotifier.
// It just inherits the underlying ResponseWriter's CloseNotify method.
func (r *ResponseRecorder) CloseNotify() <-chan bool {
if cn, ok := r.ResponseWriter.(http.CloseNotifier); ok {
return cn.CloseNotify()
}
panic("not a CloseNotifier")
}