Commit 1b17072a authored by Thomas Hansen's avatar Thomas Hansen

gzip middleware now strips encoding header

parent 7d46108c
...@@ -5,9 +5,7 @@ package fastcgi ...@@ -5,9 +5,7 @@ package fastcgi
import ( import (
"errors" "errors"
"fmt"
"io" "io"
"io/ioutil"
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
...@@ -105,11 +103,11 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) ...@@ -105,11 +103,11 @@ func (h Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error)
} }
w.WriteHeader(resp.StatusCode) w.WriteHeader(resp.StatusCode)
body, err := ioutil.ReadAll(resp.Body) // Write the response body
fmt.Printf("%s", body) _, err = io.Copy(w, resp.Body)
fmt.Printf("%d\n", resp.StatusCode) if err != nil {
fmt.Printf("%d\n", len(body)) return http.StatusBadGateway, err
w.Write(body) }
return resp.StatusCode, nil return resp.StatusCode, nil
} }
...@@ -196,11 +194,7 @@ func (h Handler) buildEnv(r *http.Request, rule Rule) (map[string]string, error) ...@@ -196,11 +194,7 @@ func (h Handler) buildEnv(r *http.Request, rule Rule) (map[string]string, error)
for field, val := range r.Header { for field, val := range r.Header {
header := strings.ToUpper(field) header := strings.ToUpper(field)
header = headerNameReplacer.Replace(header) header = headerNameReplacer.Replace(header)
// We don't want to pass the encoding header to prevent the fastcgi server from gzipping env["HTTP_"+header] = strings.Join(val, ", ")
// TODO: is there a better way.
if header != "ACCEPT_ENCODING" {
env["HTTP_"+header] = strings.Join(val, ", ")
}
} }
return env, nil return env, nil
......
...@@ -33,6 +33,7 @@ func (g Gzip) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) { ...@@ -33,6 +33,7 @@ func (g Gzip) ServeHTTP(w http.ResponseWriter, r *http.Request) (int, error) {
return g.Next.ServeHTTP(w, r) return g.Next.ServeHTTP(w, r)
} }
r.Header.Del("Accept-Encoding")
w.Header().Set("Content-Encoding", "gzip") w.Header().Set("Content-Encoding", "gzip")
gzipWriter := gzip.NewWriter(w) gzipWriter := gzip.NewWriter(w)
defer gzipWriter.Close() defer gzipWriter.Close()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment