From ceadcfece95100d9924caee123e6f1fe0d4f71c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Wed, 3 Aug 2022 20:30:59 +0800 Subject: [PATCH] =?UTF-8?q?HTTP=E6=BA=90=E7=AB=99=E6=9C=89=E5=A4=9A?= =?UTF-8?q?=E4=B8=AAL2=E8=8A=82=E7=82=B9=E6=97=B6=E5=8F=91=E7=94=9F?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E6=97=B6=E4=BC=9A=E4=B8=BB=E5=8A=A8=E5=B0=9D?= =?UTF-8?q?=E8=AF=95=E4=B8=8B=E4=B8=80=E4=B8=AAL2=E8=8A=82=E7=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_request_ln.go | 4 ++-- internal/nodes/http_request_reverse_proxy.go | 13 +++++++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/internal/nodes/http_request_ln.go b/internal/nodes/http_request_ln.go index d6426d5..03e1676 100644 --- a/internal/nodes/http_request_ln.go +++ b/internal/nodes/http_request_ln.go @@ -16,6 +16,6 @@ func (this *HTTPRequest) checkLnRequest() bool { return false } -func (this *HTTPRequest) getLnOrigin() *serverconfigs.OriginConfig { - return nil +func (this *HTTPRequest) getLnOrigin(excludingNodeIds []int64) (originConfig *serverconfigs.OriginConfig, lnNodeId int64, hasMultipleNodes bool) { + return nil, 0, false } diff --git a/internal/nodes/http_request_reverse_proxy.go b/internal/nodes/http_request_reverse_proxy.go index 62017a7..adbcd22 100644 --- a/internal/nodes/http_request_reverse_proxy.go +++ b/internal/nodes/http_request_reverse_proxy.go @@ -24,20 +24,24 @@ func (this *HTTPRequest) doReverseProxy() { var retries = 3 var failedOriginIds []int64 + var failedLnNodeIds []int64 for i := 0; i < retries; i++ { - originId, shouldRetry := this.doOriginRequest(failedOriginIds, i == 0, i == retries-1) + originId, lnNodeId, shouldRetry := this.doOriginRequest(failedOriginIds, failedLnNodeIds, i == 0, i == retries-1) if !shouldRetry { break } if originId > 0 { failedOriginIds = append(failedOriginIds, originId) } + if lnNodeId > 0 { + failedLnNodeIds = append(failedLnNodeIds, lnNodeId) + } } } // 请求源站 -func (this *HTTPRequest) doOriginRequest(failedOriginIds []int64, isFirstTry bool, isLastRetry bool) (originId int64, shouldRetry bool) { +func (this *HTTPRequest) doOriginRequest(failedOriginIds []int64, failedLnNodeIds []int64, isFirstTry bool, isLastRetry bool) (originId int64, lnNodeId int64, shouldRetry bool) { // 对URL的处理 var stripPrefix = this.reverseProxy.StripPrefix var requestURI = this.reverseProxy.RequestURI @@ -59,8 +63,9 @@ func (this *HTTPRequest) doOriginRequest(failedOriginIds []int64, isFirstTry boo var origin *serverconfigs.OriginConfig // 二级节点 + var hasMultipleLnNodes = false if this.cacheRef != nil { - origin = this.getLnOrigin() + origin, lnNodeId, hasMultipleLnNodes = this.getLnOrigin(failedLnNodeIds) if origin != nil { // 强制变更原来访问的域名 requestHost = this.ReqHost @@ -262,7 +267,7 @@ func (this *HTTPRequest) doOriginRequest(failedOriginIds []int64, isFirstTry boo }) // 是否需要重试 - if originId > 0 && !isLastRetry { + if (originId > 0 || (lnNodeId > 0 && hasMultipleLnNodes)) && !isLastRetry { shouldRetry = true this.uri = oldURI // 恢复备份