From 67a0d069446ffb67dd3d3f3fbd8c52e673e93e6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Thu, 20 Jul 2023 16:42:54 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=93=E5=AD=98=E6=9D=A1=E4=BB=B6=E4=B8=80?= =?UTF-8?q?=E4=BA=9B=E6=97=A0=E6=B3=95=E5=8C=B9=E9=85=8D=E7=9A=84=E6=83=85?= =?UTF-8?q?=E5=86=B5=E5=9C=A8X-Cache=E4=B8=AD=E4=B9=9F=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E8=AF=A6=E6=83=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_request_cache.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/internal/nodes/http_request_cache.go b/internal/nodes/http_request_cache.go index 52ba862..efd81d3 100644 --- a/internal/nodes/http_request_cache.go +++ b/internal/nodes/http_request_cache.go @@ -38,8 +38,13 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) { // 添加 X-Cache Header var addStatusHeader = this.web.Cache.AddStatusHeader + var cacheBypassDescription = "" if addStatusHeader { defer func() { + if len(cacheBypassDescription) > 0 { + this.writer.Header().Set("X-Cache", cacheBypassDescription) + return + } var cacheStatus = this.varMapping["cache.status"] if cacheStatus != "HIT" { this.writer.Header().Set("X-Cache", cacheStatus) @@ -94,6 +99,7 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) { // 校验请求 if !this.cacheRef.MatchRequest(this.RawReq) { this.cacheRef = nil + cacheBypassDescription = "BYPASS, not match" return } @@ -106,6 +112,7 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) { if this.cacheRef.EnableRequestCachePragma { if this.RawReq.Header.Get("Cache-Control") == "no-cache" || this.RawReq.Header.Get("Pragma") == "no-cache" { this.cacheRef = nil + cacheBypassDescription = "BYPASS, Cache-Control or Pragma" return } } @@ -119,6 +126,7 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) { var key = this.Format(this.cacheRef.Key) if len(key) == 0 { this.cacheRef = nil + cacheBypassDescription = "BYPASS, empty key" return } var method = this.Method() @@ -134,6 +142,7 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) { var storage = caches.SharedManager.FindStorageWithPolicy(cachePolicy.Id) if storage == nil { this.cacheRef = nil + cacheBypassDescription = "BYPASS, no policy found" return } this.writer.cacheStorage = storage