enhance: support ETag on streamed repository archives, support If-None-Match: * (#39289)

Signed-off-by: silverwind <me@silverwind.io>
Co-authored-by: Claude (Opus 5) <noreply@anthropic.com>
Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
silverwind
2026-09-16 12:30:22 +02:00
committed by GitHub
co-authored by Claude wxiaoguang
parent 31b4d79a84
commit c04802b6b3
4 changed files with 65 additions and 9 deletions
+14 -7
View File
@@ -55,13 +55,20 @@ func CacheControlForPrivateStatic() *CacheControlOptions {
// checkIfNoneMatchIsValid tests if the header If-None-Match matches the ETag
func checkIfNoneMatchIsValid(req *http.Request, etag string) bool {
ifNoneMatch := req.Header.Get("If-None-Match")
if len(ifNoneMatch) > 0 {
for item := range strings.SplitSeq(ifNoneMatch, ",") {
item = strings.TrimPrefix(strings.TrimSpace(item), "W/") // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/ETag#directives
if item == etag {
return true
}
ifNoneMatch := strings.TrimSpace(req.Header.Get("If-None-Match"))
if ifNoneMatch == "" {
return false
}
// https://www.rfc-editor.org/rfc/rfc9110#section-13.1.2
if ifNoneMatch == "*" {
return true
}
// https://www.rfc-editor.org/rfc/rfc9110#section-8.8.3.2
etag = strings.TrimPrefix(etag, "W/")
for item := range strings.SplitSeq(ifNoneMatch, ",") {
item = strings.TrimPrefix(strings.TrimSpace(item), "W/")
if item == etag {
return true
}
}
return false