mirror of
https://github.com/TeaOSLab/EdgeNode.git
synced 2025-11-08 11:20:27 +08:00
忽略301, 302, 303, 307, 308响应中没有Location的错误提示
This commit is contained in:
@@ -104,7 +104,8 @@ func (this *HTTPClientPool) Client(req *HTTPRequest,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var transport = &http.Transport{
|
var transport = &HTTPClientTransport{
|
||||||
|
Transport: &http.Transport{
|
||||||
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||||
// 支持TOA的连接
|
// 支持TOA的连接
|
||||||
conn, err := this.handleTOA(req, ctx, network, originAddr, connectionTimeout)
|
conn, err := this.handleTOA(req, ctx, network, originAddr, connectionTimeout)
|
||||||
@@ -137,6 +138,7 @@ func (this *HTTPClientPool) Client(req *HTTPRequest,
|
|||||||
TLSHandshakeTimeout: 3 * time.Second,
|
TLSHandshakeTimeout: 3 * time.Second,
|
||||||
TLSClientConfig: tlsConfig,
|
TLSClientConfig: tlsConfig,
|
||||||
Proxy: nil,
|
Proxy: nil,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
rawClient = &http.Client{
|
rawClient = &http.Client{
|
||||||
|
|||||||
26
internal/nodes/http_client_transport.go
Normal file
26
internal/nodes/http_client_transport.go
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
// Copyright 2022 Liuxiangchao iwind.liu@gmail.com. All rights reserved. Official site: https://goedge.cn .
|
||||||
|
|
||||||
|
package nodes
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
)
|
||||||
|
|
||||||
|
const emptyHTTPLocation = "/$EmptyHTTPLocation$"
|
||||||
|
|
||||||
|
type HTTPClientTransport struct {
|
||||||
|
*http.Transport
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *HTTPClientTransport) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||||
|
resp, err := this.Transport.RoundTrip(req)
|
||||||
|
if err != nil {
|
||||||
|
return resp, err
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检查在跳转相关状态中Location是否存在
|
||||||
|
if httpStatusIsRedirect(resp.StatusCode) && len(resp.Header.Get("Location")) == 0 {
|
||||||
|
resp.Header.Set("Location", emptyHTTPLocation)
|
||||||
|
}
|
||||||
|
return resp, nil
|
||||||
|
}
|
||||||
@@ -282,6 +282,11 @@ func (this *HTTPRequest) doReverseProxy() {
|
|||||||
// 替换Location中的源站地址
|
// 替换Location中的源站地址
|
||||||
var locationHeader = resp.Header.Get("Location")
|
var locationHeader = resp.Header.Get("Location")
|
||||||
if len(locationHeader) > 0 {
|
if len(locationHeader) > 0 {
|
||||||
|
// 空Location处理
|
||||||
|
if locationHeader == emptyHTTPLocation {
|
||||||
|
resp.Header.Del("Location")
|
||||||
|
} else {
|
||||||
|
// 自动修正Location中的源站地址
|
||||||
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
|
||||||
@@ -294,6 +299,7 @@ func (this *HTTPRequest) doReverseProxy() {
|
|||||||
resp.Header.Set("Location", locationURL.String())
|
resp.Header.Set("Location", locationURL.String())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 响应Header
|
// 响应Header
|
||||||
this.writer.AddHeaders(resp.Header)
|
this.writer.AddHeaders(resp.Header)
|
||||||
|
|||||||
Reference in New Issue
Block a user