mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-07 10:40:26 +08:00
保存L2节点数据时同时记录缓存时间
This commit is contained in:
@@ -1557,7 +1557,7 @@ func (this *HTTPRequest) fixRequestHeader(header http.Header) {
|
||||
|
||||
// 处理自定义Response Header
|
||||
func (this *HTTPRequest) processResponseHeaders(statusCode int) {
|
||||
responseHeader := this.writer.Header()
|
||||
var responseHeader = this.writer.Header()
|
||||
|
||||
// 删除/添加/替换Header
|
||||
// TODO 实现AddTrailers
|
||||
|
||||
@@ -379,7 +379,7 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) {
|
||||
}
|
||||
|
||||
// 支持 If-None-Match
|
||||
if !isPartialCache && len(eTag) > 0 && this.requestHeader("If-None-Match") == eTag {
|
||||
if !this.isLnRequest && !isPartialCache && len(eTag) > 0 && this.requestHeader("If-None-Match") == eTag {
|
||||
// 自定义Header
|
||||
this.processResponseHeaders(http.StatusNotModified)
|
||||
this.writer.WriteHeader(http.StatusNotModified)
|
||||
@@ -390,7 +390,7 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) {
|
||||
}
|
||||
|
||||
// 支持 If-Modified-Since
|
||||
if !isPartialCache && len(modifiedTime) > 0 && this.requestHeader("If-Modified-Since") == modifiedTime {
|
||||
if !this.isLnRequest && !isPartialCache && len(modifiedTime) > 0 && this.requestHeader("If-Modified-Since") == modifiedTime {
|
||||
// 自定义Header
|
||||
this.processResponseHeaders(http.StatusNotModified)
|
||||
this.writer.WriteHeader(http.StatusNotModified)
|
||||
@@ -403,6 +403,11 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) {
|
||||
this.processResponseHeaders(reader.Status())
|
||||
this.addExpiresHeader(reader.ExpiresAt())
|
||||
|
||||
// 返回上级节点过期时间
|
||||
if this.isLnRequest {
|
||||
respHeader.Set(LNExpiresHeader, types.String(reader.ExpiresAt()))
|
||||
}
|
||||
|
||||
// 输出Body
|
||||
if this.RawReq.Method == http.MethodHead {
|
||||
this.writer.WriteHeader(reader.Status())
|
||||
|
||||
@@ -8,6 +8,10 @@ import (
|
||||
"github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs"
|
||||
)
|
||||
|
||||
const (
|
||||
LNExpiresHeader = "X-Edge-Ln-Expires"
|
||||
)
|
||||
|
||||
func (this *HTTPRequest) checkLnRequest() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -283,12 +283,28 @@ func (this *HTTPWriter) PrepareCache(resp *http.Response, size int64) {
|
||||
}
|
||||
}
|
||||
|
||||
var expiredAt = utils.UnixTime() + life
|
||||
var expiresAt = utils.UnixTime() + life
|
||||
|
||||
if this.req.isLnRequest {
|
||||
// 返回上级节点过期时间
|
||||
this.SetHeader(LNExpiresHeader, []string{types.String(expiresAt)})
|
||||
} else {
|
||||
var expiresHeader = this.Header().Get(LNExpiresHeader)
|
||||
if len(expiresHeader) > 0 {
|
||||
this.Header().Del(LNExpiresHeader)
|
||||
|
||||
var expiresHeaderInt64 = types.Int64(expiresHeader)
|
||||
if expiresHeaderInt64 > 0 {
|
||||
expiresAt = expiresHeaderInt64
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var cacheKey = this.req.cacheKey
|
||||
if this.isPartial {
|
||||
cacheKey += caches.SuffixPartial
|
||||
}
|
||||
cacheWriter, err := storage.OpenWriter(cacheKey, expiredAt, this.StatusCode(), size, cacheRef.MaxSizeBytes(), this.isPartial)
|
||||
cacheWriter, err := storage.OpenWriter(cacheKey, expiresAt, this.StatusCode(), size, cacheRef.MaxSizeBytes(), this.isPartial)
|
||||
if err != nil {
|
||||
if err == caches.ErrEntityTooLarge && addStatusHeader {
|
||||
this.Header().Set("X-Cache", "BYPASS, entity too large")
|
||||
|
||||
@@ -4,6 +4,10 @@
|
||||
|
||||
package nodes
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
func (this *HTTPWriter) canSendfile() (*os.File, bool) {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user