From 9f4559024694b4c78a198b0d4d7ceb83219f9fab Mon Sep 17 00:00:00 2001 From: wenyifan Date: Thu, 4 Aug 2022 09:40:30 +0800 Subject: [PATCH] =?UTF-8?q?connect=20Target=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- http.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/http.go b/http.go index 8c59ad8..bcf86de 100644 --- a/http.go +++ b/http.go @@ -52,6 +52,7 @@ func (c *httpConnector) ConnectContext(ctx context.Context, conn net.Conn, netwo ua = DefaultUserAgent } + origAddress := address if 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("Proxy-Connection", "keep-alive") + if origAddress != address { + req.Header.Set("Target", origAddress) + } + user := opts.User if user == nil { user = c.User @@ -163,6 +168,10 @@ func (h *httpHandler) handleRequest(conn net.Conn, req *http.Request) { } host := req.Host + actualTarget := req.Header.Get("Target") + if actualTarget != "" { + host = actualTarget + } if _, port, _ := net.SplitHostPort(host); port == "" { 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("Target") resp := &http.Response{ ProtoMajor: 1,