mirror of
https://github.com/go-gitea/gitea.git
synced 2026-09-20 03:33:39 +09:00
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:
co-authored by
Claude
wxiaoguang
parent
31b4d79a84
commit
c04802b6b3
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user