mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-14 07:30:25 +08:00
缓存条件一些无法匹配的情况在X-Cache中也增加详情
This commit is contained in:
@@ -38,8 +38,13 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) {
|
|||||||
|
|
||||||
// 添加 X-Cache Header
|
// 添加 X-Cache Header
|
||||||
var addStatusHeader = this.web.Cache.AddStatusHeader
|
var addStatusHeader = this.web.Cache.AddStatusHeader
|
||||||
|
var cacheBypassDescription = ""
|
||||||
if addStatusHeader {
|
if addStatusHeader {
|
||||||
defer func() {
|
defer func() {
|
||||||
|
if len(cacheBypassDescription) > 0 {
|
||||||
|
this.writer.Header().Set("X-Cache", cacheBypassDescription)
|
||||||
|
return
|
||||||
|
}
|
||||||
var cacheStatus = this.varMapping["cache.status"]
|
var cacheStatus = this.varMapping["cache.status"]
|
||||||
if cacheStatus != "HIT" {
|
if cacheStatus != "HIT" {
|
||||||
this.writer.Header().Set("X-Cache", cacheStatus)
|
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) {
|
if !this.cacheRef.MatchRequest(this.RawReq) {
|
||||||
this.cacheRef = nil
|
this.cacheRef = nil
|
||||||
|
cacheBypassDescription = "BYPASS, not match"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,6 +112,7 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) {
|
|||||||
if this.cacheRef.EnableRequestCachePragma {
|
if this.cacheRef.EnableRequestCachePragma {
|
||||||
if this.RawReq.Header.Get("Cache-Control") == "no-cache" || this.RawReq.Header.Get("Pragma") == "no-cache" {
|
if this.RawReq.Header.Get("Cache-Control") == "no-cache" || this.RawReq.Header.Get("Pragma") == "no-cache" {
|
||||||
this.cacheRef = nil
|
this.cacheRef = nil
|
||||||
|
cacheBypassDescription = "BYPASS, Cache-Control or Pragma"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -119,6 +126,7 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) {
|
|||||||
var key = this.Format(this.cacheRef.Key)
|
var key = this.Format(this.cacheRef.Key)
|
||||||
if len(key) == 0 {
|
if len(key) == 0 {
|
||||||
this.cacheRef = nil
|
this.cacheRef = nil
|
||||||
|
cacheBypassDescription = "BYPASS, empty key"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
var method = this.Method()
|
var method = this.Method()
|
||||||
@@ -134,6 +142,7 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) {
|
|||||||
var storage = caches.SharedManager.FindStorageWithPolicy(cachePolicy.Id)
|
var storage = caches.SharedManager.FindStorageWithPolicy(cachePolicy.Id)
|
||||||
if storage == nil {
|
if storage == nil {
|
||||||
this.cacheRef = nil
|
this.cacheRef = nil
|
||||||
|
cacheBypassDescription = "BYPASS, no policy found"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
this.writer.cacheStorage = storage
|
this.writer.cacheStorage = storage
|
||||||
|
|||||||
Reference in New Issue
Block a user