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:
func TestEnsureVaryHeaderNoDuplicate(t *testing.T) {
handler := GzipHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Add(vary, acceptEncoding)
w.Write([]byte("test"))
w.(io.Closer).Close()
}))
req := httptest.NewRequest("GET", "/", nil)
req.Header.Set(acceptEncoding, "gzip")
w := httptest.NewRecorder()
handler.ServeHTTP(w, req)
assert.Equal(t, w.Header()[vary], []string{acceptEncoding})
}
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.