summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/NYTimes/gziphandler/gzip.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2017-11-13 09:09:58 -0800
committerGitHub <noreply@github.com>2017-11-13 09:09:58 -0800
commit1329aa51b605cb54ba9aae3a82a0a87b881fb7b3 (patch)
tree93cbf354ab894a560fc2cef8ef685d681b4ff889 /vendor/github.com/NYTimes/gziphandler/gzip.go
parent7304a61ef597970be3031b14e652fb3a4df44304 (diff)
downloadchat-1329aa51b605cb54ba9aae3a82a0a87b881fb7b3.tar.gz
chat-1329aa51b605cb54ba9aae3a82a0a87b881fb7b3.tar.bz2
chat-1329aa51b605cb54ba9aae3a82a0a87b881fb7b3.zip
Updating server dependancies. (#7816)
Diffstat (limited to 'vendor/github.com/NYTimes/gziphandler/gzip.go')
-rw-r--r--vendor/github.com/NYTimes/gziphandler/gzip.go12
1 files changed, 10 insertions, 2 deletions
diff --git a/vendor/github.com/NYTimes/gziphandler/gzip.go b/vendor/github.com/NYTimes/gziphandler/gzip.go
index b6af9115a..13ee34a42 100644
--- a/vendor/github.com/NYTimes/gziphandler/gzip.go
+++ b/vendor/github.com/NYTimes/gziphandler/gzip.go
@@ -82,6 +82,7 @@ type GzipResponseWriter struct {
buf []byte // Holds the first part of the write before reaching the minSize or the end of the write.
contentTypes []string // Only compress if the response is one of these content-types. All are accepted if empty.
+ flushed bool // Indicate if the stream was already flushed
}
// Write appends data to the gzip writer.
@@ -150,7 +151,9 @@ func (w *GzipResponseWriter) startGzip() error {
// WriteHeader just saves the response code until close or GZIP effective writes.
func (w *GzipResponseWriter) WriteHeader(code int) {
- w.code = code
+ if w.code == 0 {
+ w.code = code
+ }
}
// init graps a new gzip writer from the gzipWriterPool and writes the correct
@@ -167,7 +170,8 @@ func (w *GzipResponseWriter) init() {
func (w *GzipResponseWriter) Close() error {
if w.gw == nil {
// Gzip not trigged yet, write out regular response.
- if w.code != 0 {
+ // WriteHeader only if it wasn't already wrote by a Flush
+ if !w.flushed && w.code != 0 {
w.ResponseWriter.WriteHeader(w.code)
}
if w.buf != nil {
@@ -195,7 +199,11 @@ func (w *GzipResponseWriter) Flush() {
}
if fw, ok := w.ResponseWriter.(http.Flusher); ok {
+ if !w.flushed && w.code != 0 {
+ w.ResponseWriter.WriteHeader(w.code)
+ }
fw.Flush()
+ w.flushed = true
}
}