mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-15 23:26:36 +08:00
开启缓存后覆盖源站的ETag和Last-Modified
This commit is contained in:
@@ -181,25 +181,22 @@ func (this *HTTPRequest) doCacheRead() (shouldStop bool) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ETag
|
// ETag
|
||||||
|
// 这里强制设置ETag,如果先前源站设置了ETag,将会被覆盖,避免因为源站的ETag导致源站返回304 Not Modified
|
||||||
var respHeader = this.writer.Header()
|
var respHeader = this.writer.Header()
|
||||||
var eTag = respHeader.Get("ETag")
|
var eTag = ""
|
||||||
var lastModifiedAt = reader.LastModified()
|
var lastModifiedAt = reader.LastModified()
|
||||||
if len(eTag) == 0 {
|
if lastModifiedAt > 0 {
|
||||||
if lastModifiedAt > 0 {
|
eTag = "\"" + strconv.FormatInt(lastModifiedAt, 10) + "\""
|
||||||
eTag = "\"" + strconv.FormatInt(lastModifiedAt, 10) + "\""
|
respHeader.Del("Etag")
|
||||||
respHeader["ETag"] = []string{eTag}
|
respHeader["ETag"] = []string{eTag}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 支持 Last-Modified
|
// 支持 Last-Modified
|
||||||
var modifiedTime = respHeader.Get("Last-Modified")
|
// 这里强制设置Last-Modified,如果先前源站设置了Last-Modified,将会被覆盖,避免因为源站的Last-Modified导致源站返回304 Not Modified
|
||||||
if len(modifiedTime) == 0 {
|
var modifiedTime = ""
|
||||||
if lastModifiedAt > 0 {
|
if lastModifiedAt > 0 {
|
||||||
modifiedTime = time.Unix(lastModifiedAt, 0).Format("Mon, 02 Jan 2006 15:04:05 GMT")
|
modifiedTime = time.Unix(lastModifiedAt, 0).Format("Mon, 02 Jan 2006 15:04:05 GMT")
|
||||||
if len(respHeader.Get("Last-Modified")) == 0 {
|
respHeader.Set("Last-Modified", modifiedTime)
|
||||||
respHeader.Set("Last-Modified", modifiedTime)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 支持 If-None-Match
|
// 支持 If-None-Match
|
||||||
|
|||||||
Reference in New Issue
Block a user