From c64cf218b0a82d144e779454817eb0371a5002a8 Mon Sep 17 00:00:00 2001 From: Tw Date: Mon, 11 Apr 2016 12:16:41 +0800 Subject: [PATCH] http.CloseNotifier implementation for http.ResponseWriter wrapper Signed-off-by: Tw --- middleware/gzip/gzip.go | 9 +++++++++ middleware/recorder.go | 9 +++++++++ 2 files changed, 18 insertions(+) diff --git a/middleware/gzip/gzip.go b/middleware/gzip/gzip.go index 9d75b351e..f24a94aab 100644 --- a/middleware/gzip/gzip.go +++ b/middleware/gzip/gzip.go @@ -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") +} diff --git a/middleware/recorder.go b/middleware/recorder.go index ab30e3053..50f4811cf 100644 --- a/middleware/recorder.go +++ b/middleware/recorder.go @@ -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") +}