From dba4dcb4a586d0d18366098c79f9ac465c28cc27 Mon Sep 17 00:00:00 2001 From: Matthew Holt Date: Sun, 26 Apr 2015 22:53:47 -0600 Subject: [PATCH] gzip strips Accept-Encoding header after using it --- middleware/fastcgi/fastcgi.go | 6 +----- middleware/gzip/gzip.go | 3 +++ 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/middleware/fastcgi/fastcgi.go b/middleware/fastcgi/fastcgi.go index 9a9994d78..7f780379f 100644 --- a/middleware/fastcgi/fastcgi.go +++ b/middleware/fastcgi/fastcgi.go @@ -196,11 +196,7 @@ func (h Handler) buildEnv(r *http.Request, rule Rule) (map[string]string, error) for field, val := range r.Header { header := strings.ToUpper(field) header = headerNameReplacer.Replace(header) - // We don't want to pass the encoding header to prevent the fastcgi server from gzipping - // TODO: is there a better way. - if header != "ACCEPT_ENCODING" { - env["HTTP_"+header] = strings.Join(val, ", ") - } + env["HTTP_"+header] = strings.Join(val, ", ") } return env, nil diff --git a/middleware/gzip/gzip.go b/middleware/gzip/gzip.go index c9f62bc42..694118321 100644 --- a/middleware/gzip/gzip.go +++ b/middleware/gzip/gzip.go @@ -33,6 +33,9 @@ func (g Gzip) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) { return g.Next.ServeHTTP(w, r) } + // Delete this header so gzipping isn't repeated later in the chain + r.Header.Del("Accept-Encoding") + w.Header().Set("Content-Encoding", "gzip") gzipWriter := gzip.NewWriter(w) defer gzipWriter.Close()