From d9189e6212d1ecd3cd88a6344fcfda125d416ccc Mon Sep 17 00:00:00 2001 From: nadoo <287492+nadoo@users.noreply.github.com> Date: Sun, 13 Oct 2019 21:42:16 +0800 Subject: [PATCH] http: add Host header in CONNECT request --- conf.go | 1 + go.mod | 4 ++-- go.sum | 6 ++++-- proxy/http/http.go | 12 +++++------- 4 files changed, 12 insertions(+), 11 deletions(-) diff --git a/conf.go b/conf.go index 020fc2f..16424f0 100644 --- a/conf.go +++ b/conf.go @@ -143,6 +143,7 @@ func usage() { fmt.Fprintf(os.Stderr, " AES-128-CFB AES-128-CTR AES-192-CFB AES-192-CTR AES-256-CFB AES-256-CTR CHACHA20-IETF XCHACHA20 CHACHA20 RC4-MD5\n") fmt.Fprintf(os.Stderr, " Alias:\n") fmt.Fprintf(os.Stderr, " chacha20-ietf-poly1305 = AEAD_CHACHA20_POLY1305, xchacha20-ietf-poly1305 = AEAD_XCHACHA20_POLY1305\n") + fmt.Fprintf(os.Stderr, " Plain: DUMMY\n") fmt.Fprintf(os.Stderr, "\n") fmt.Fprintf(os.Stderr, "SSR scheme:\n") diff --git a/go.mod b/go.mod index 5fdc362..e89ec0f 100644 --- a/go.mod +++ b/go.mod @@ -14,8 +14,8 @@ require ( github.com/tjfoc/gmsm v1.0.1 // indirect github.com/xtaci/kcp-go v5.4.11+incompatible github.com/xtaci/lossyconn v0.0.0-20190602105132-8df528c0c9ae // indirect - golang.org/x/crypto v0.0.0-20191010185427-af544f31c8ac - golang.org/x/net v0.0.0-20191009170851-d66e71096ffb // indirect + golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 + golang.org/x/net v0.0.0-20191011234655-491137f69257 // indirect ) // Replace dependency modules with local developing copy diff --git a/go.sum b/go.sum index 9bc78a6..cc828af 100644 --- a/go.sum +++ b/go.sum @@ -34,9 +34,11 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20191010185427-af544f31c8ac h1:/b4NMZurYfBIQyRMqaPGMDeUrSW6gU7/7Hv6owY1Vjk= golang.org/x/crypto v0.0.0-20191010185427-af544f31c8ac/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550 h1:ObdrDkeb4kJdCP557AjRjq69pTHfNouLtWZG7j9rPN8= +golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= -golang.org/x/net v0.0.0-20191009170851-d66e71096ffb h1:TR699M2v0qoKTOHxeLgp6zPqaQNs74f01a/ob9W0qko= -golang.org/x/net v0.0.0-20191009170851-d66e71096ffb/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20191011234655-491137f69257 h1:ry8e2D+cwaV6hk7lb3aRTjjZo24shrbK0e11QEOkTIg= +golang.org/x/net v0.0.0-20191011234655-491137f69257/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20191009170203-06d7bd2c5f4f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= diff --git a/proxy/http/http.go b/proxy/http/http.go index a7d89b6..3fa08d0 100644 --- a/proxy/http/http.go +++ b/proxy/http/http.go @@ -154,8 +154,7 @@ func (s *HTTP) Serve(c net.Conn) { // GET http://example.com/a/index.htm HTTP/1.1 --> // GET /a/index.htm HTTP/1.1 - u.Scheme = "" - u.Host = "" + u.Scheme, u.Host = "", "" uri := u.String() var reqBuf bytes.Buffer @@ -198,7 +197,6 @@ func (s *HTTP) Serve(c net.Conn) { c.Write(respBuf.Bytes()) io.Copy(c, respR) - } func (s *HTTP) servHTTPS(method, requestURI, proto string, c net.Conn) { @@ -240,9 +238,9 @@ func (s *HTTP) Dial(network, addr string) (net.Conn, error) { } var buf bytes.Buffer - buf.Write([]byte("CONNECT " + addr + " HTTP/1.1\r\n")) - // TODO: add host header for compatibility? - buf.Write([]byte("Proxy-Connection: Keep-Alive\r\n")) + buf.WriteString("CONNECT " + addr + " HTTP/1.1\r\n") + buf.WriteString("Host: " + addr + "\r\n") + buf.WriteString("Proxy-Connection: Keep-Alive\r\n") if s.user != "" && s.password != "" { auth := s.user + ":" + s.password @@ -250,7 +248,7 @@ func (s *HTTP) Dial(network, addr string) (net.Conn, error) { } // header ended - buf.Write([]byte("\r\n")) + buf.WriteString("\r\n") _, err = rc.Write(buf.Bytes()) if err != nil { return nil, err