From 125b25ea27761dfde6088f81e5ee361c6675723e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E7=A5=A5=E8=B6=85?= Date: Wed, 17 Jan 2024 15:17:19 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A6=82=E6=9E=9C=E6=BA=90=E7=AB=99=E8=AF=B7?= =?UTF-8?q?=E6=B1=82=E5=93=8D=E5=BA=94=E4=B8=AD=E6=B2=A1=E6=9C=89Content-T?= =?UTF-8?q?ype=EF=BC=8C=E5=88=99=E4=B8=8D=E8=AE=BE=E7=BD=AEContent-Type?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_request_reverse_proxy.go | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/internal/nodes/http_request_reverse_proxy.go b/internal/nodes/http_request_reverse_proxy.go index bef1f86..0f2beb0 100644 --- a/internal/nodes/http_request_reverse_proxy.go +++ b/internal/nodes/http_request_reverse_proxy.go @@ -381,11 +381,20 @@ func (this *HTTPRequest) doOriginRequest(failedOriginIds []int64, failedLnNodeId return } + if resp == nil { + this.write50x(requestErr, http.StatusBadGateway, "Failed to read origin site", "源站读取失败", true) + return + } + + // fix Content-Type + if resp.Header["Content-Type"] == nil { + resp.Header["Content-Type"] = []string{} + } + // 40x && 50x *failStatusCode = resp.StatusCode - if resp != nil && - ((resp.StatusCode >= 500 && resp.StatusCode < 510 && this.reverseProxy.Retry50X) || - (resp.StatusCode >= 403 && resp.StatusCode <= 404 && this.reverseProxy.Retry40X)) && + if ((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 { @@ -397,8 +406,7 @@ func (this *HTTPRequest) doOriginRequest(failedOriginIds []int64, failedLnNodeId } // 尝试从缓存中恢复 - if resp != nil && - resp.StatusCode >= 500 && // support 50X only + if resp.StatusCode >= 500 && // support 50X only resp.StatusCode < 510 && this.cacheCanTryStale && this.web.Cache.Stale != nil &&