忽略301, 302, 303, 307, 308响应中没有Location的错误提示

This commit is contained in:
GoEdgeLab
2022-05-19 20:16:40 +08:00
parent 38603416ee
commit 6f13d6f560
3 changed files with 72 additions and 38 deletions

View File

@@ -282,16 +282,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 != this.ReqHost && (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"
}
// 空Location处理
if locationHeader == emptyHTTPLocation {
resp.Header.Del("Location")
} else {
// 自动修正Location中的源站地址
locationURL, err := url.Parse(locationHeader)
if err == nil && locationURL.Host != this.ReqHost && (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())
resp.Header.Set("Location", locationURL.String())
}
}
}