From 7334b8f6378d69cb47af450d6cd48a6e01376ed1 Mon Sep 17 00:00:00 2001 From: David Leadbeater Date: Wed, 24 Dec 2025 14:36:23 +1100 Subject: [PATCH] Add a Vary header when content negotiation happens Without this, if a cache first sees a compressed version of the request, it will return that for potentially any future requests, even if they don't request compression. --- src/pages.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/pages.go b/src/pages.go index aea858e..a598de1 100644 --- a/src/pages.go +++ b/src/pages.go @@ -216,6 +216,7 @@ func getPage(w http.ResponseWriter, r *http.Request) error { // we only offer `/.git-pages/archive.tar` and not the `.tar.gz`/`.tar.zst` variants // because HTTP can already request compression using the `Content-Encoding` mechanism acceptedEncodings := ParseAcceptEncodingHeader(r.Header.Get("Accept-Encoding")) + w.Header().Add("Vary", "Accept-Encoding") negotiated := acceptedEncodings.Negotiate("zstd", "gzip", "identity") if negotiated != "" { w.Header().Set("Content-Encoding", negotiated) @@ -327,6 +328,7 @@ func getPage(w http.ResponseWriter, r *http.Request) error { var offeredEncodings []string acceptedEncodings := ParseAcceptEncodingHeader(r.Header.Get("Accept-Encoding")) + w.Header().Add("Vary", "Accept-Encoding") negotiatedEncoding := true switch entry.GetTransform() { case Transform_Identity: