From d209e9611a7e1fc83d13fac5b97318dc7979acd5 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Sat, 26 Aug 2023 15:46:45 +0800 Subject: [PATCH] =?UTF-8?q?=E6=BA=90=E7=AB=99=E8=BF=94=E5=9B=9E50X?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E4=B9=9F=E5=8F=AF=E4=BB=A5=E5=B0=9D=E8=AF=95?= =?UTF-8?q?=E4=BD=BF=E7=94=A8=E8=BF=87=E6=97=B6=E7=BC=93=E5=AD=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_request_reverse_proxy.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/internal/nodes/http_request_reverse_proxy.go b/internal/nodes/http_request_reverse_proxy.go index a8c6a67..8496eb4 100644 --- a/internal/nodes/http_request_reverse_proxy.go +++ b/internal/nodes/http_request_reverse_proxy.go @@ -7,6 +7,7 @@ import ( "github.com/TeaOSLab/EdgeCommon/pkg/serverconfigs/shared" "github.com/TeaOSLab/EdgeNode/internal/remotelogs" "github.com/TeaOSLab/EdgeNode/internal/utils" + "github.com/iwind/TeaGo/lists" "github.com/iwind/TeaGo/types" "io" "net/http" @@ -389,6 +390,20 @@ func (this *HTTPRequest) doOriginRequest(failedOriginIds []int64, failedLnNodeId return } + // 尝试从缓存中恢复 + if resp != nil && + resp.StatusCode >= 500 && // support 50X only + resp.StatusCode < 510 && + this.cacheCanTryStale && + this.web.Cache.Stale != nil && + this.web.Cache.Stale.IsOn && + (len(this.web.Cache.Stale.Status) == 0 || lists.ContainsInt(this.web.Cache.Stale.Status, resp.StatusCode)) { + var ok = this.doCacheRead(true) + if ok { + return + } + } + // 记录相关数据 this.originStatus = int32(resp.StatusCode)