You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If the inner HTTP handler sets a Vary: Accept-Encoding header, then as the gzip middleware will always add in the same header, the output will have two identical headers.
I don't think the HTTP spec explicitly disallows you from having the same key/value appearing twice in the headers but it feels tidier to only have one instance of it.
The text was updated successfully, but these errors were encountered:
I'm not sure there's a great way to fix this because technically the gziphandler package is adding the header BEFORE your inner handler, so technically your inner handler should be checking if the header already exists like so:
// if something else already set Vary: Accept-Encoding, don't set it twiceif!strings.Contains(w.Header().Get(vary), acceptEncoding) {
w.Header().Add(vary, acceptEncoding)
}
Get() only returns the first element of a slice. Have to iterate over the slice. Also use canonical values.
func AddVary(w http.ResponseWriter, value string) {
value = textproto.CanonicalMIMEHeaderKey(value)
for _, v := range w.Header()["Vary"] {
if textproto.CanonicalMIMEHeaderKey(v) == value {
return
}
}
w.Header().Add("Vary", value)
}
If the inner HTTP handler sets a
Vary: Accept-Encoding
header, then as the gzip middleware will always add in the same header, the output will have two identical headers.Here is a failing test case:
I don't think the HTTP spec explicitly disallows you from having the same key/value appearing twice in the headers but it feels tidier to only have one instance of it.
The text was updated successfully, but these errors were encountered: