From 7cf41ace4736ec608e0c74f90aa0b295a88d18f6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Thu, 14 Jul 2022 11:03:34 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BC=93=E5=AD=98=E6=9D=A1=E4=BB=B6=E4=B8=AD?= =?UTF-8?q?=E5=90=AF=E7=94=A8=E5=AE=A2=E6=88=B7=E7=AB=AF=E8=BF=87=E6=9C=9F?= =?UTF-8?q?=E6=97=B6=E9=97=B4=E5=90=8E=EF=BC=8C=E8=87=AA=E5=8A=A8=E5=88=A0?= =?UTF-8?q?=E9=99=A4=E6=BA=90=E7=AB=99=E7=9A=84Cache-Control=20Header?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_request_cache.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/nodes/http_request_cache.go b/internal/nodes/http_request_cache.go index 7583682..1e31937 100644 --- a/internal/nodes/http_request_cache.go +++ b/internal/nodes/http_request_cache.go @@ -375,6 +375,7 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) { if !this.isLnRequest && !isPartialCache && len(eTag) > 0 && this.requestHeader("If-None-Match") == eTag { // 自定义Header this.processResponseHeaders(http.StatusNotModified) + this.addExpiresHeader(reader.ExpiresAt()) this.writer.WriteHeader(http.StatusNotModified) this.isCached = true this.cacheRef = nil @@ -386,6 +387,7 @@ func (this *HTTPRequest) doCacheRead(useStale bool) (shouldStop bool) { if !this.isLnRequest && !isPartialCache && len(modifiedTime) > 0 && this.requestHeader("If-Modified-Since") == modifiedTime { // 自定义Header this.processResponseHeaders(http.StatusNotModified) + this.addExpiresHeader(reader.ExpiresAt()) this.writer.WriteHeader(http.StatusNotModified) this.isCached = true this.cacheRef = nil @@ -575,10 +577,12 @@ func (this *HTTPRequest) addExpiresHeader(expiresAt int64) { if this.cacheRef.ExpiresTime.Overwrite || len(this.writer.Header().Get("Expires")) == 0 { if this.cacheRef.ExpiresTime.AutoCalculate { this.writer.Header().Set("Expires", time.Unix(utils.GMTUnixTime(expiresAt), 0).Format("Mon, 2 Jan 2006 15:04:05")+" GMT") + this.writer.Header().Del("Cache-Control") } else if this.cacheRef.ExpiresTime.Duration != nil { var duration = this.cacheRef.ExpiresTime.Duration.Duration() if duration > 0 { this.writer.Header().Set("Expires", utils.GMTTime(time.Now().Add(duration)).Format("Mon, 2 Jan 2006 15:04:05")+" GMT") + this.writer.Header().Del("Cache-Control") } } }