nytimes / gziphandler

Go middleware to gzip HTTP responses
https://godoc.org/github.com/NYTimes/gziphandler
Apache License 2.0
868 stars 129 forks source link

If not handleContenttype it buffers entire content #64

Closed rlk833 closed 6 years ago

rlk833 commented 6 years ago

IF I'm reading line 166 correctly:

if len(w.buf) >= w.minSize && handleContentType(w.contentTypes, w) && w.Header().Get(contentEncoding) == "" {

Then even if the buffer accumulates to over the minsize but it fails contenttype or content coding is set it will buffer the entire output stream before writing it out at close.

The handlecontenttype and get(contentencoding) should be the very first test on the first write and if it fails then from then on just flush directly to the real response writer and don't buffer anymore since these settings can't change once the writing has started.