mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-08 03:00:27 +08:00
如果Header中Location字段含有跟源站一样的地址,则自动修改为当前域名
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user