From acd0c1bcd50931269fa7047df88eb3413159ce5e Mon Sep 17 00:00:00 2001 From: SALLEYRON Julien Date: Fri, 5 Jan 2018 02:26:03 +0100 Subject: [PATCH] GzipResponse must implement CloseNotifier if ResponseWriter implement it --- glide.lock | 2 +- vendor/github.com/NYTimes/gziphandler/gzip.go | 17 +++++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/glide.lock b/glide.lock index 0bc9610db..09e1be294 100644 --- a/glide.lock +++ b/glide.lock @@ -426,7 +426,7 @@ imports: repo: https://github.com/ijc25/Gotty.git vcs: git - name: github.com/NYTimes/gziphandler - version: d6f46609c7629af3a02d791a4666866eed3cbd3e + version: 47ca22a0aeea4c9ceddfb935d818d636d934c312 - name: github.com/ogier/pflag version: 45c278ab3607870051a2ea9040bb85fcb8557481 - name: github.com/opencontainers/go-digest diff --git a/vendor/github.com/NYTimes/gziphandler/gzip.go b/vendor/github.com/NYTimes/gziphandler/gzip.go index 901c4554a..b3cb8315b 100644 --- a/vendor/github.com/NYTimes/gziphandler/gzip.go +++ b/vendor/github.com/NYTimes/gziphandler/gzip.go @@ -84,6 +84,14 @@ type GzipResponseWriter struct { contentTypes []string // Only compress if the response is one of these content-types. All are accepted if empty. } +type GzipResponseWriterWithCloseNotify struct { + *GzipResponseWriter +} + +func (w *GzipResponseWriterWithCloseNotify) CloseNotify() <-chan bool { + return w.ResponseWriter.(http.CloseNotifier).CloseNotify() +} + // Write appends data to the gzip writer. func (w *GzipResponseWriter) Write(b []byte) (int, error) { // If content type is not set. @@ -264,7 +272,6 @@ func GzipHandlerWithOpts(opts ...option) (func(http.Handler) http.Handler, error return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Add(vary, acceptEncoding) - if acceptsGzip(r) { gw := &GzipResponseWriter{ ResponseWriter: w, @@ -274,7 +281,13 @@ func GzipHandlerWithOpts(opts ...option) (func(http.Handler) http.Handler, error } defer gw.Close() - h.ServeHTTP(gw, r) + if _, ok := w.(http.CloseNotifier); ok { + gwcn := GzipResponseWriterWithCloseNotify{gw} + h.ServeHTTP(gwcn, r) + } else { + h.ServeHTTP(gw, r) + } + } else { h.ServeHTTP(w, r) }