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