支持自动添加X-Cache Header

This commit is contained in:
刘祥超
2021-05-12 16:10:03 +08:00
parent a9ec78afb4
commit ebf4d41290

View File

@@ -15,6 +15,15 @@ func (this *HTTPRequest) doCacheRead() (shouldStop bool) {
if this.web.Cache == nil || !this.web.Cache.IsOn || len(this.web.Cache.CacheRefs) == 0 {
return
}
var addStatusHeader = this.web.Cache.AddStatusHeader
if addStatusHeader {
defer func() {
cacheStatus := this.varMapping["cache.status"]
if cacheStatus != "HIT" {
this.writer.Header().Set("X-Cache", cacheStatus)
}
}()
}
cachePolicy := sharedNodeConfig.HTTPCachePolicy
if cachePolicy == nil || !cachePolicy.IsOn {
@@ -115,6 +124,9 @@ func (this *HTTPRequest) doCacheRead() (shouldStop bool) {
return
}
if addStatusHeader {
this.writer.Header().Set("X-Cache", "HIT")
}
this.processResponseHeaders(reader.Status())
// 输出Body