gzip strips Accept-Encoding header after using it

This commit is contained in:
Matthew Holt 2015-04-26 22:53:47 -06:00
parent 7d46108c12
commit dba4dcb4a5
2 changed files with 4 additions and 5 deletions

View File

@ -196,12 +196,8 @@ 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, ", ")
}
}
return env, nil
}

View File

@ -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()