ginuerzh / gost

GO Simple Tunnel - a simple tunnel written in golang
MIT License
15.84k stars 2.47k forks source link

[Feature Request] Replace Host header when connecting to upstream HTTP CONNECT proxy #717

Open iBug opened 3 years ago

iBug commented 3 years ago

Will you add a ?host= flag for -F http:// proxy forwarding?

Expected behavior: Whatever host client requests, gost should send to upstream CONNECT example.com:443 HTTP/1.1 and Host: example.com:443 and otherwise proxy as usual.

Use case: This helps accessing other HTTP sites hosted on the same server, particularly useful for CDNs.

iBug commented 3 years ago

I patched gost locally so ?host= works for sni:// now. Not yet sure about HTTP proxy.

diff --git a/sni.go b/sni.go
index e57d4a0..a4e00f3 100644
--- a/sni.go
+++ b/sni.go
@@ -103,6 +103,10 @@ func (h *sniHandler) Handle(conn net.Conn) {
            conn.RemoteAddr(), conn.LocalAddr(), err)
        return
    }
+   hosts := h.options.Node.Values["host"]
+   if len(hosts) > 0 {
+       host = hosts[0]
+   }

    _, sport, _ := net.SplitHostPort(h.options.Host)
    if sport == "" {