From 0c5950e9e890977f003d9044854fc180ffa55c1d Mon Sep 17 00:00:00 2001 From: nadoo <287492+nadoo@users.noreply.github.com> Date: Sun, 16 Jul 2017 20:13:01 +0800 Subject: [PATCH] fixed a bug in upstream http proxy. --- README.md | 4 ++-- http.go | 14 ++++++++------ main.go | 2 +- strategy.go | 2 +- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 6d0a37c..0e20069 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Examples: -listen on :8443, serve as http/socks5 proxy on the same port. glider -l ss://AEAD_CHACHA20_POLY1305:pass@:8443 - -listen on 0.0.0.0:8443 as a shadowsocks server. + -listen on 0.0.0.0:8443 as a ss server. glider -l socks5://:1080 -v -listen on :1080 as a socks5 proxy server, in verbose mode. @@ -102,5 +102,5 @@ systemctl start glider.service ``` ## Thanks -- [go-shadowsocks2](https://github.com/shadowsocks/go-shadowsocks2): the core ss protocol support +- [go-ss2](https://github.com/shadowsocks/go-shadowsocks2): the core ss protocol support - [gost](https://github.com/ginuerzh/gost): ideas and inspirations \ No newline at end of file diff --git a/http.go b/http.go index b42766d..205ea40 100644 --- a/http.go +++ b/http.go @@ -6,6 +6,7 @@ package main import ( "bufio" "bytes" + "errors" "fmt" "io" "net" @@ -157,6 +158,7 @@ func (s *httpproxy) servHTTPS(method, requestURI, proto string, c net.Conn) { logf("failed to dial: %v", err) return } + c.Write([]byte("HTTP/1.0 200 Connection established\r\n\r\n")) logf("proxy-https %s <-> %s", c.RemoteAddr(), requestURI) @@ -172,26 +174,26 @@ func (s *httpproxy) servHTTPS(method, requestURI, proto string, c net.Conn) { // Dial connects to the address addr on the network net via the proxy. func (s *httpproxy) Dial(network, addr string) (net.Conn, error) { - c, err := s.GetProxy().Dial("tcp", s.addr) + rc, err := s.GetProxy().Dial("tcp", s.addr) if err != nil { logf("dial to %s error: %s", s.addr, err) return nil, err } - if c, ok := c.(*net.TCPConn); ok { + if c, ok := rc.(*net.TCPConn); ok { c.SetKeepAlive(true) } - c.Write([]byte("CONNECT " + addr + " HTTP/1.0\r\n")) + rc.Write([]byte("CONNECT " + addr + " HTTP/1.0\r\n")) // c.Write([]byte("Proxy-Connection: Keep-Alive\r\n")) var b [1024]byte - n, err := c.Read(b[:]) + n, err := rc.Read(b[:]) if bytes.Contains(b[:n], []byte("200")) { - return c, err + return rc, err } - return nil, err + return nil, errors.New("cound not connect remote address:" + addr) } // parseFirstLine parses "GET /foo HTTP/1.1" OR "HTTP/1.1 200 OK" into its three parts. diff --git a/main.go b/main.go index 48b64ff..470bb19 100644 --- a/main.go +++ b/main.go @@ -10,7 +10,7 @@ import ( "syscall" ) -const version = "0.1.1" +const version = "0.1.3" var config struct { Verbose bool diff --git a/strategy.go b/strategy.go index aa8eaa7..acddc56 100644 --- a/strategy.go +++ b/strategy.go @@ -48,7 +48,7 @@ func (p *strategyProxy) NextProxy() Proxy { } if !found { - logf("NO AVALIABLE PROXY FOUND! please check your network or proxy server settings.") + logf("NO AVAILABLE PROXY FOUND! please check your network or proxy server settings.") } return p.forwarders[p.idx]