0
Fork 0
mirror of https://github.com/caddyserver/caddy.git synced 2025-01-06 22:40:31 -05:00

gzip: added Vary: Accept-Encoding to response header.

When the downstream is cache server or CDN, it is important.
This commit is contained in:
Tatsuhiko Kubo 2015-11-14 05:59:38 +09:00
parent fc6afe2a8b
commit 69662d4d7d
2 changed files with 4 additions and 0 deletions

View file

@ -47,6 +47,7 @@ outer:
r.Header.Del("Accept-Encoding")
w.Header().Set("Content-Encoding", "gzip")
w.Header().Set("Vary", "Accept-Encoding")
gzipWriter, err := newWriter(c, w)
if err != nil {
// should not happen

View file

@ -87,6 +87,9 @@ func nextFunc(shouldGzip bool) middleware.Handler {
if w.Header().Get("Content-Encoding") != "gzip" {
return 0, fmt.Errorf("Content-Encoding must be gzip, found %v", r.Header.Get("Content-Encoding"))
}
if w.Header().Get("Vary") != "Accept-Encoding" {
return 0, fmt.Errorf("Vary must be Accept-Encoding, found %v", r.Header.Get("Vary"))
}
if _, ok := w.(gzipResponseWriter); !ok {
return 0, fmt.Errorf("ResponseWriter should be gzipResponseWriter, found %T", w)
}