From 92045abeca83a30e120b3f96fe66b1c9d1161ef2 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Wed, 15 Nov 2023 19:06:15 +0800 Subject: [PATCH] =?UTF-8?q?=E6=BA=90=E7=AB=99=E6=94=AF=E6=8C=81404?= =?UTF-8?q?=E5=86=85=E5=AE=B9=E8=87=AA=E5=8A=A8=E9=87=8D=E8=AF=95=E5=85=B6?= =?UTF-8?q?=E4=BB=96=E6=BA=90=E7=AB=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_request_reverse_proxy.go | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/internal/nodes/http_request_reverse_proxy.go b/internal/nodes/http_request_reverse_proxy.go index 8b5ee29..e37aea6 100644 --- a/internal/nodes/http_request_reverse_proxy.go +++ b/internal/nodes/http_request_reverse_proxy.go @@ -27,9 +27,10 @@ func (this *HTTPRequest) doReverseProxy() { var failedOriginIds []int64 var failedLnNodeIds []int64 + var failStatusCode int for i := 0; i < retries; i++ { - originId, lnNodeId, shouldRetry := this.doOriginRequest(failedOriginIds, failedLnNodeIds, i == 0, i == retries-1) + originId, lnNodeId, shouldRetry := this.doOriginRequest(failedOriginIds, failedLnNodeIds, i == 0, i == retries-1, &failStatusCode) if !shouldRetry { break } @@ -43,7 +44,7 @@ func (this *HTTPRequest) doReverseProxy() { } // 请求源站 -func (this *HTTPRequest) doOriginRequest(failedOriginIds []int64, failedLnNodeIds []int64, isFirstTry bool, isLastRetry bool) (originId int64, lnNodeId int64, shouldRetry bool) { +func (this *HTTPRequest) doOriginRequest(failedOriginIds []int64, failedLnNodeIds []int64, isFirstTry bool, isLastRetry bool, failStatusCode *int) (originId int64, lnNodeId int64, shouldRetry bool) { // 对URL的处理 var stripPrefix = this.reverseProxy.StripPrefix var requestURI = this.reverseProxy.RequestURI @@ -91,6 +92,10 @@ func (this *HTTPRequest) doOriginRequest(failedOriginIds []int64, failedLnNodeId } if origin == nil { origin = this.reverseProxy.NextOrigin(requestCall) + if origin != nil && origin.Id > 0 && (*failStatusCode >= 403 && *failStatusCode <= 404) && lists.ContainsInt64(failedOriginIds, origin.Id) { + this.writeCode(*failStatusCode, "", "") + return + } } requestCall.CallResponseCallbacks(this.writer) if origin == nil { @@ -376,11 +381,11 @@ func (this *HTTPRequest) doOriginRequest(failedOriginIds []int64, failedLnNodeId return } - // 50x + // 40x && 50x + *failStatusCode = resp.StatusCode if resp != nil && - resp.StatusCode >= 500 && - resp.StatusCode < 510 && - this.reverseProxy.Retry50X && + ((resp.StatusCode >= 500 && resp.StatusCode < 510 && this.reverseProxy.Retry50X) || + (resp.StatusCode >= 403 && resp.StatusCode <= 404 && this.reverseProxy.Retry40X)) && (originId > 0 || (lnNodeId > 0 && hasMultipleLnNodes)) && !isLastRetry { if resp.Body != nil {