From e0a349c81655c6c43a82d44ca52240d73e5b9d83 Mon Sep 17 00:00:00 2001 From: GoEdgeLab Date: Tue, 7 Jun 2022 11:25:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=BA=90=E7=AB=99=E4=BB=8Eht?= =?UTF-8?q?tp=E8=B7=B3=E8=BD=AC=E5=88=B0https=E5=AF=BC=E8=87=B4=E6=97=A0?= =?UTF-8?q?=E9=99=90=E5=BE=AA=E7=8E=AF=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/nodes/http_request_reverse_proxy.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/internal/nodes/http_request_reverse_proxy.go b/internal/nodes/http_request_reverse_proxy.go index 34199be..7984cd9 100644 --- a/internal/nodes/http_request_reverse_proxy.go +++ b/internal/nodes/http_request_reverse_proxy.go @@ -290,13 +290,23 @@ func (this *HTTPRequest) doReverseProxy() { locationURL, err := url.Parse(locationHeader) if err == nil && locationURL.Host != this.ReqHost && (locationURL.Host == originAddr || strings.HasPrefix(originAddr, locationURL.Host+":")) { locationURL.Host = this.ReqHost + + var oldScheme = locationURL.Scheme + + // 尝试和当前Scheme一致 if this.IsHTTP { locationURL.Scheme = "http" } else if this.IsHTTPS { locationURL.Scheme = "https" } - resp.Header.Set("Location", locationURL.String()) + // 如果和当前URL一样,则可能是http -> https,防止无限循环 + if locationURL.String() == this.URL() { + locationURL.Scheme = oldScheme + resp.Header.Set("Location", locationURL.String()) + } else { + resp.Header.Set("Location", locationURL.String()) + } } } }