mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-12-09 11:20:25 +08:00
修复源站从http跳转到https导致无限循环的问题
This commit is contained in:
@@ -290,13 +290,23 @@ func (this *HTTPRequest) doReverseProxy() {
|
|||||||
locationURL, err := url.Parse(locationHeader)
|
locationURL, err := url.Parse(locationHeader)
|
||||||
if err == nil && locationURL.Host != this.ReqHost && (locationURL.Host == originAddr || strings.HasPrefix(originAddr, locationURL.Host+":")) {
|
if err == nil && locationURL.Host != this.ReqHost && (locationURL.Host == originAddr || strings.HasPrefix(originAddr, locationURL.Host+":")) {
|
||||||
locationURL.Host = this.ReqHost
|
locationURL.Host = this.ReqHost
|
||||||
|
|
||||||
|
var oldScheme = locationURL.Scheme
|
||||||
|
|
||||||
|
// 尝试和当前Scheme一致
|
||||||
if this.IsHTTP {
|
if this.IsHTTP {
|
||||||
locationURL.Scheme = "http"
|
locationURL.Scheme = "http"
|
||||||
} else if this.IsHTTPS {
|
} else if this.IsHTTPS {
|
||||||
locationURL.Scheme = "https"
|
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())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user