summaryrefslogtreecommitdiffhomepage
path: root/middleware/gzip
diff options
context:
space:
mode:
authorTatsuhiko Kubo <[email protected]>2015-11-14 05:59:38 +0900
committerTatsuhiko Kubo <[email protected]>2015-11-14 06:11:37 +0900
commit69662d4d7d37fc408a3792d3c54dd875a5c199e6 (patch)
tree8516a4d205be1e5c2a3e870ce3063909427fbc36 /middleware/gzip
parentfc6afe2a8bab007f95fd571c963bdd1019be5ab7 (diff)
downloadcaddy-69662d4d7d37fc408a3792d3c54dd875a5c199e6.tar.gz
caddy-69662d4d7d37fc408a3792d3c54dd875a5c199e6.zip
gzip: added Vary: Accept-Encoding to response header.
When the downstream is cache server or CDN, it is important.
Diffstat (limited to 'middleware/gzip')
-rw-r--r--middleware/gzip/gzip.go1
-rw-r--r--middleware/gzip/gzip_test.go3
2 files changed, 4 insertions, 0 deletions
diff --git a/middleware/gzip/gzip.go b/middleware/gzip/gzip.go
index 9acec5ebc..e2d447753 100644
--- a/middleware/gzip/gzip.go
+++ b/middleware/gzip/gzip.go
@@ -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
diff --git a/middleware/gzip/gzip_test.go b/middleware/gzip/gzip_test.go
index 8d49e8e27..3e7bed996 100644
--- a/middleware/gzip/gzip_test.go
+++ b/middleware/gzip/gzip_test.go
@@ -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)
}