From 56d50908416902811a12dca78073f334e526ba4b Mon Sep 17 00:00:00 2001 From: wweir Date: Wed, 16 Jan 2019 22:37:18 +0800 Subject: [PATCH] Separate http_proxy interface setting for some case --- conf/conf.go | 8 ++++---- conf/sower.toml | 4 ++-- main.go | 4 ++-- proxy/http_proxy.go | 8 ++------ 4 files changed, 10 insertions(+), 14 deletions(-) diff --git a/conf/conf.go b/conf/conf.go index 1035166..9ba883a 100644 --- a/conf/conf.go +++ b/conf/conf.go @@ -20,9 +20,9 @@ var Conf = struct { Cipher string `toml:"cipher"` Password string `toml:"password"` - ServerPort string `toml:"server_port"` - ServerAddr string `toml:"server_addr"` - HTTPProxyPort string `toml:"http_proxy_port"` + ServerPort string `toml:"server_port"` + ServerAddr string `toml:"server_addr"` + HTTPProxy string `toml:"http_proxy"` DNSServer string `toml:"dns_server"` ClientIP string `toml:"client_ip"` @@ -41,7 +41,7 @@ func init() { flag.StringVar(&Conf.Password, "p", "12345678", "password") flag.StringVar(&Conf.ServerPort, "P", "5533", "server mode listen port") flag.StringVar(&Conf.ServerAddr, "s", "", "server IP (run in client mode if set)") - flag.StringVar(&Conf.HTTPProxyPort, "H", "", "http proxy listen port") + flag.StringVar(&Conf.HTTPProxy, "H", "", "http proxy listen addr") flag.StringVar(&Conf.DNSServer, "d", "114.114.114.114", "client dns server") flag.StringVar(&Conf.ClientIP, "c", "127.0.0.1", "client dns service redirect IP") diff --git a/conf/sower.toml b/conf/sower.toml index 1283b65..a525714 100644 --- a/conf/sower.toml +++ b/conf/sower.toml @@ -2,8 +2,8 @@ net_type="TCP" cipher="AES_128_GCM" password="12345678" server_port="5533" -server_addr="remote-server:5533" # replce it to remote server -http_proxy_port="8080" +# server_addr="remote-server:5533" # replce it to remote server +http_proxy=":8080" # eg: 192.168.0.2:8080 dns_server="223.5.5.5" # Alibaba public dns client_ip="127.0.0.1" # clear_dns_cache="killall -HUP mDNSResponder" diff --git a/main.go b/main.go index 1012dec..e378f4f 100644 --- a/main.go +++ b/main.go @@ -15,9 +15,9 @@ func main() { proxy.StartServer(conf.NetType, conf.ServerPort, conf.Cipher, conf.Password) } else { - if conf.HTTPProxyPort != "" { + if conf.HTTPProxy != "" { go proxy.StartHttpProxy(conf.NetType, conf.ServerAddr, - conf.Cipher, conf.Password, conf.ClientIP, conf.HTTPProxyPort) + conf.Cipher, conf.Password, conf.HTTPProxy) } go dns.StartDNS(conf.DNSServer, conf.ClientIP, conf.ClientIPNet) diff --git a/proxy/http_proxy.go b/proxy/http_proxy.go index a0ce912..5304ae1 100644 --- a/proxy/http_proxy.go +++ b/proxy/http_proxy.go @@ -12,15 +12,11 @@ import ( "github.com/wweir/sower/shadow" ) -func StartHttpProxy(netType, server, cipher, password, listenIP, port string) { - if port[0] != ':' { - port = ":" + port - } - +func StartHttpProxy(netType, server, cipher, password, addr string) { client := NewClient(netType) srv := &http.Server{ - Addr: listenIP + port, + Addr: addr, Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { if r.Method == http.MethodConnect { httpsProxy(w, r, client, server, cipher, password)