缓存在响应中可以添加Age Header

This commit is contained in:
刘祥超
2021-12-02 09:54:48 +08:00
parent f6dfd6acec
commit 061253b4c3

View File

@@ -208,11 +208,15 @@ func (this *HTTPRequest) doCacheRead() (shouldStop bool) {
}
// 设置cache.age变量
this.varMapping["cache.age"] = strconv.FormatInt(reader.ExpiresAt()-utils.UnixTime(), 10)
var age = strconv.FormatInt(reader.ExpiresAt()-utils.UnixTime(), 10)
this.varMapping["cache.age"] = age
if addStatusHeader {
this.writer.Header().Set("X-Cache", "HIT, "+refType+", "+reader.TypeName())
}
if this.web.Cache.AddAgeHeader {
this.writer.Header().Set("Age", age)
}
// ETag
// 这里强制设置ETag如果先前源站设置了ETag将会被覆盖避免因为源站的ETag导致源站返回304 Not Modified