Skip to content

Commit

Permalink
Only flush once startGzip has been called
Browse files Browse the repository at this point in the history
This fixes nytimes#58 and the failing test case from
23770e4. This prevents the underlying Flusher from writing the
wrong status code or writing headers before Content-Encoding has
been set.
  • Loading branch information
tmthrgd committed Nov 9, 2017
1 parent 23770e4 commit cb0f3d9
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions gzip.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,18 @@ func (w *responseWriter) Close() error {
// underlying http.ResponseWriter if it is an http.Flusher.
// This makes GzipResponseWriter an http.Flusher.
func (w *responseWriter) Flush() {
if w.gw != nil {
w.gw.Flush()
if w.gw == nil {
// Fix for NYTimes/gziphandler#58:
// Only flush once startGzip has been
// called.
//
// Flush is thus a no-op until the written
// body exceeds minSize.
return
}

w.gw.Flush()

if fw, ok := w.ResponseWriter.(http.Flusher); ok {
fw.Flush()
}
Expand Down

0 comments on commit cb0f3d9

Please sign in to comment.