fix(httpcache): raw files return 304 after a change when the new commit is older (#39435) (#39591)

Backport #39435

Co-authored-by: breken <support@brekfuz.com>
This commit is contained in:
Giteabot
2026-10-04 06:39:06 -07:00
committed by GitHub
parent efee6d7ce4
commit 02fd18970b
2 changed files with 16 additions and 1 deletions
+3 -1
View File
@@ -99,7 +99,9 @@ func handleGenericETagTimeCache(req *http.Request, w http.ResponseWriter, etag s
return true
}
}
if lastModified != nil && !lastModified.IsZero() {
// https://www.rfc-editor.org/rfc/rfc9110#section-13.1.3
// A recipient MUST ignore If-Modified-Since if the request contains an If-None-Match header field
if lastModified != nil && !lastModified.IsZero() && req.Header.Get("If-None-Match") == "" {
ifModifiedSince := req.Header.Get("If-Modified-Since")
if ifModifiedSince != "" {
t, err := time.Parse(http.TimeFormat, ifModifiedSince)
+13
View File
@@ -76,6 +76,19 @@ func TestHandleGenericETagCache(t *testing.T) {
wantHeaders: map[string]string{"Last-Modified": lastModified, "Cache-Control": "", "Etag": weakEtag},
wantStatus: http.StatusNotModified,
},
{
name: "If-Modified-Since without If-None-Match",
reqHeaders: map[string]string{"If-Modified-Since": lastModified},
wantHandled: true,
wantHeaders: map[string]string{"Last-Modified": lastModified, "Cache-Control": "", "Etag": matchedEtag},
wantStatus: http.StatusNotModified,
},
{
name: "Mismatched If-None-Match takes precedence over If-Modified-Since",
reqHeaders: map[string]string{"If-None-Match": `"mismatched-etag"`, "If-Modified-Since": lastModified},
wantHandled: false,
wantHeaders: map[string]string{"Last-Modified": lastModified, "Cache-Control": cacheControl, "Etag": matchedEtag},
},
{
name: "Multiple Matched If-None-Match",
reqHeaders: map[string]string{"If-None-Match": `"mismatched-etag", ` + matchedEtag},