From 2e79b5a5e78003ccd0f27fc896f99465423f4761 Mon Sep 17 00:00:00 2001 From: Chris Lajoie Date: Mon, 27 Jan 2020 09:24:40 -0700 Subject: [PATCH] Fix infinite buffering of SSE responses when gzip is enabled (#739) --- proxy/gzip/gzip_handler.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/proxy/gzip/gzip_handler.go b/proxy/gzip/gzip_handler.go index 9cdf70d10..f59f805b6 100644 --- a/proxy/gzip/gzip_handler.go +++ b/proxy/gzip/gzip_handler.go @@ -21,6 +21,7 @@ import ( const ( headerVary = "Vary" + headerAccept = "Accept" headerAcceptEncoding = "Accept-Encoding" headerContentEncoding = "Content-Encoding" headerContentType = "Content-Type" @@ -28,6 +29,8 @@ const ( encodingGzip = "gzip" ) +var blacklistedAcceptContentTypes = []string{"text/event-stream"} + var gzipWriterPool = sync.Pool{ New: func() interface{} { return gzip.NewWriter(nil) }, } @@ -110,5 +113,11 @@ func isCompressable(header http.Header, contentTypes *regexp.Regexp) bool { } func acceptsGzip(r *http.Request) bool { + accept := r.Header.Get(headerAccept) + for _, contentType := range blacklistedAcceptContentTypes { + if strings.Contains(accept, contentType) { + return false + } + } return strings.Contains(r.Header.Get(headerAcceptEncoding), encodingGzip) }