Permalink
Browse files

Move defer statement into http handler function (#219)

  • Loading branch information...
robbawebba authored and nilslice committed Jan 8, 2018
1 parent 7194ae2 commit c8640a82dd704ce51676a457b4a2ec72ec67e316
Showing with 4 additions and 3 deletions.
  1. +4 −3 system/api/gzip.go
View
@@ -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)
}

0 comments on commit c8640a8

Please sign in to comment.