Skip to content

Commit

Permalink
Fix infinite buffering of SSE responses when gzip is enabled (#739)
Browse files Browse the repository at this point in the history
  • Loading branch information
ctlajoie authored and Aaron Hurt committed Jan 27, 2020
1 parent df63a7a commit 2e79b5a
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions proxy/gzip/gzip_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@ import (

const (
headerVary = "Vary"
headerAccept = "Accept"
headerAcceptEncoding = "Accept-Encoding"
headerContentEncoding = "Content-Encoding"
headerContentType = "Content-Type"
headerContentLength = "Content-Length"
encodingGzip = "gzip"
)

var blacklistedAcceptContentTypes = []string{"text/event-stream"}

var gzipWriterPool = sync.Pool{
New: func() interface{} { return gzip.NewWriter(nil) },
}
Expand Down Expand Up @@ -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)
}

0 comments on commit 2e79b5a

Please sign in to comment.