修复源站从http跳转到https导致无限循环的问题

This commit is contained in:
刘祥超
2022-06-07 11:25:09 +08:00
parent 13e718742d
commit ad843d9d10

View File

@@ -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())
}
}
}
}