diff --git a/internal/nodes/http_client_pool.go b/internal/nodes/http_client_pool.go index 6f5cb26..2503247 100644 --- a/internal/nodes/http_client_pool.go +++ b/internal/nodes/http_client_pool.go @@ -142,11 +142,12 @@ func (this *HTTPClientPool) Client(req *HTTPRequest, rawClient = &http.Client{ Timeout: readTimeout, Transport: transport, - CheckRedirect: func(req *http.Request, via []*http.Request) error { + CheckRedirect: func(targetReq *http.Request, via []*http.Request) error { + // 是否跟随 if followRedirects { var schemeIsSame = true for _, r := range via { - if r.URL.Scheme != req.URL.Scheme { + if r.URL.Scheme != targetReq.URL.Scheme { schemeIsSame = false break } diff --git a/internal/nodes/http_request_reverse_proxy.go b/internal/nodes/http_request_reverse_proxy.go index a79234a..37ea03d 100644 --- a/internal/nodes/http_request_reverse_proxy.go +++ b/internal/nodes/http_request_reverse_proxy.go @@ -279,6 +279,22 @@ func (this *HTTPRequest) doReverseProxy() { } } + // 替换Location中的源站地址 + var locationHeader = resp.Header.Get("Location") + if len(locationHeader) > 0 { + locationURL, err := url.Parse(locationHeader) + if err == nil && (locationURL.Host == originAddr || strings.HasPrefix(originAddr, locationURL.Host+":")) { + locationURL.Host = this.ReqHost + if this.IsHTTP { + locationURL.Scheme = "http" + } else if this.IsHTTPS { + locationURL.Scheme = "https" + } + + resp.Header.Set("Location", locationURL.String()) + } + } + // 响应Header this.writer.AddHeaders(resp.Header) this.processResponseHeaders(resp.StatusCode)