mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-27 06:03:48 +03:00
gzip: Avoid duplicated Vary header (#2939)
This commit is contained in:
parent
4b68de8418
commit
cd66b62083
1 changed files with 13 additions and 1 deletions
|
@ -130,7 +130,19 @@ type gzipResponseWriter struct {
|
|||
func (w *gzipResponseWriter) WriteHeader(code int) {
|
||||
w.Header().Del("Content-Length")
|
||||
w.Header().Set("Content-Encoding", "gzip")
|
||||
w.Header().Add("Vary", "Accept-Encoding")
|
||||
varyList, exist := w.Header()["Vary"]
|
||||
shouldAddVary := true
|
||||
if exist {
|
||||
for _, vary := range varyList {
|
||||
if vary == "Accept-Encoding" {
|
||||
shouldAddVary = false
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
if shouldAddVary {
|
||||
w.Header().Add("Vary", "Accept-Encoding")
|
||||
}
|
||||
originalEtag := w.Header().Get("ETag")
|
||||
if originalEtag != "" && !strings.HasPrefix(originalEtag, "W/") {
|
||||
w.Header().Set("ETag", "W/"+originalEtag)
|
||||
|
|
Loading…
Reference in a new issue