Commit ae2e0900 authored by Matt Holt's avatar Matt Holt

Merge pull request #339 from cubicdaiya/vary-accept-encoding

gzip: added Vary: Accept-Encoding to response header.
parents fc6afe2a 69662d4d
...@@ -47,6 +47,7 @@ outer: ...@@ -47,6 +47,7 @@ outer:
r.Header.Del("Accept-Encoding") r.Header.Del("Accept-Encoding")
w.Header().Set("Content-Encoding", "gzip") w.Header().Set("Content-Encoding", "gzip")
w.Header().Set("Vary", "Accept-Encoding")
gzipWriter, err := newWriter(c, w) gzipWriter, err := newWriter(c, w)
if err != nil { if err != nil {
// should not happen // should not happen
......
...@@ -87,6 +87,9 @@ func nextFunc(shouldGzip bool) middleware.Handler { ...@@ -87,6 +87,9 @@ func nextFunc(shouldGzip bool) middleware.Handler {
if w.Header().Get("Content-Encoding") != "gzip" { if w.Header().Get("Content-Encoding") != "gzip" {
return 0, fmt.Errorf("Content-Encoding must be gzip, found %v", r.Header.Get("Content-Encoding")) 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 { if _, ok := w.(gzipResponseWriter); !ok {
return 0, fmt.Errorf("ResponseWriter should be gzipResponseWriter, found %T", w) return 0, fmt.Errorf("ResponseWriter should be gzipResponseWriter, found %T", w)
} }
......
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