mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-05 18:44:58 +03:00
gzip middleware now strips encoding header
This commit is contained in:
parent
7d46108c12
commit
1b17072a89
2 changed files with 7 additions and 12 deletions
|
@ -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)
|
||||||
}
|
}
|
||||||
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,12 +194,8 @@ 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
|
|
||||||
// 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
|
return env, nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -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()
|
||||||
|
|
Loading…
Reference in a new issue