diff options
author | Steve Manuel <nilslice@gmail.com> | 2018-01-08 09:37:04 -0700 |
---|---|---|
committer | Steve Manuel <nilslice@gmail.com> | 2018-01-08 09:37:04 -0700 |
commit | b1f5024ed10580b8437bc2e7f8f90f21fb14bc33 (patch) | |
tree | eae20671da895543c97d647c77034db43140c2a6 /system/api/gzip.go | |
parent | 3c8d90cf0d5e2af0a9a6adf508fffda7d636b9a6 (diff) | |
parent | acfd3deeb7efc8929dd4001acfa58fcac74203a1 (diff) |
Merge branch 'ponzu-dev' of https://github.com/ponzu-cms/ponzu into ponzu-dev
Diffstat (limited to 'system/api/gzip.go')
-rw-r--r-- | system/api/gzip.go | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/system/api/gzip.go b/system/api/gzip.go index be5a51b..02f1535 100644 --- a/system/api/gzip.go +++ b/system/api/gzip.go @@ -20,11 +20,13 @@ func Gzip(next http.HandlerFunc) http.HandlerFunc { if strings.Contains(req.Header.Get("Accept-Encoding"), "gzip") { // gzip response data res.Header().Set("Content-Encoding", "gzip") + gzWriter := gzip.NewWriter(res) + defer gzWriter.Close() var gzres gzipResponseWriter if pusher, ok := res.(http.Pusher); ok { - gzres = gzipResponseWriter{res, pusher, gzip.NewWriter(res)} + gzres = gzipResponseWriter{res, pusher, gzWriter} } else { - gzres = gzipResponseWriter{res, nil, gzip.NewWriter(res)} + gzres = gzipResponseWriter{res, nil, gzWriter} } next.ServeHTTP(gzres, req) @@ -43,7 +45,6 @@ type gzipResponseWriter struct { } func (gzw gzipResponseWriter) Write(p []byte) (int, error) { - defer gzw.gw.Close() return gzw.gw.Write(p) } |