connect Target修复

This commit is contained in:
wenyifan 2022-08-04 09:40:30 +08:00
parent 6d72721cab
commit 9f45590246

10
http.go
View File

@ -52,6 +52,7 @@ func (c *httpConnector) ConnectContext(ctx context.Context, conn net.Conn, netwo
ua = DefaultUserAgent ua = DefaultUserAgent
} }
origAddress := address
if opts.Host != "" { if opts.Host != "" {
address = opts.Host address = opts.Host
} }
@ -70,6 +71,10 @@ func (c *httpConnector) ConnectContext(ctx context.Context, conn net.Conn, netwo
req.Header.Set("User-Agent", ua) req.Header.Set("User-Agent", ua)
req.Header.Set("Proxy-Connection", "keep-alive") req.Header.Set("Proxy-Connection", "keep-alive")
if origAddress != address {
req.Header.Set("Target", origAddress)
}
user := opts.User user := opts.User
if user == nil { if user == nil {
user = c.User user = c.User
@ -163,6 +168,10 @@ func (h *httpHandler) handleRequest(conn net.Conn, req *http.Request) {
} }
host := req.Host host := req.Host
actualTarget := req.Header.Get("Target")
if actualTarget != "" {
host = actualTarget
}
if _, port, _ := net.SplitHostPort(host); port == "" { if _, port, _ := net.SplitHostPort(host); port == "" {
host = net.JoinHostPort(host, "80") host = net.JoinHostPort(host, "80")
} }
@ -180,6 +189,7 @@ func (h *httpHandler) handleRequest(conn net.Conn, req *http.Request) {
} }
req.Header.Del("Gost-Target") req.Header.Del("Gost-Target")
req.Header.Del("Target")
resp := &http.Response{ resp := &http.Response{
ProtoMajor: 1, ProtoMajor: 1,