From e3d9aba5a708cff0a245f073004a300df291d4a7 Mon Sep 17 00:00:00 2001 From: Jinqiu Yu Date: Mon, 20 Feb 2017 18:32:46 +0800 Subject: [PATCH 1/7] Fix PAC addr lost bug when bind to 0.0.0.0 address --- proxy.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/proxy.go b/proxy.go index 601ac65e..549da550 100644 --- a/proxy.go +++ b/proxy.go @@ -160,12 +160,14 @@ func (hp *httpProxy) Serve(wg *sync.WaitGroup, quit <-chan struct{}) { }() host, _, _ := net.SplitHostPort(hp.addr) var pacURL string - if host == "" || host == "0.0.0.0" { - pacURL = fmt.Sprintf("http://:%s/pac", hp.port) - } else if hp.addrInPAC == "" { - pacURL = fmt.Sprintf("http://%s/pac", hp.addr) - } else { + if hp.addrInPAC != "" { pacURL = fmt.Sprintf("http://%s/pac", hp.addrInPAC) + } else { + if host == "" || host == "0.0.0.0" { + pacURL = fmt.Sprintf("http://:%s/pac", hp.port) + } else { + pacURL = fmt.Sprintf("http://%s/pac", hp.addrInPAC) + } } info.Printf("COW %s listen http %s, PAC url %s\n", version, hp.addr, pacURL) From 17a29674880e7777cbc50919341791730c0881d8 Mon Sep 17 00:00:00 2001 From: Jinqiu Yu Date: Tue, 21 Feb 2017 10:52:03 +0800 Subject: [PATCH 2/7] Fix pacURL error when host is specified --- proxy.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/proxy.go b/proxy.go index 549da550..f5fe7ba3 100644 --- a/proxy.go +++ b/proxy.go @@ -166,7 +166,7 @@ func (hp *httpProxy) Serve(wg *sync.WaitGroup, quit <-chan struct{}) { if host == "" || host == "0.0.0.0" { pacURL = fmt.Sprintf("http://:%s/pac", hp.port) } else { - pacURL = fmt.Sprintf("http://%s/pac", hp.addrInPAC) + pacURL = fmt.Sprintf("http://%s/pac", hp.addr) } } info.Printf("COW %s listen http %s, PAC url %s\n", version, hp.addr, pacURL) From bd6d38d2e0cae75e8fbe2684cde41de065a91e8d Mon Sep 17 00:00:00 2001 From: Jinqiu Yu Date: Tue, 21 Feb 2017 11:10:10 +0800 Subject: [PATCH 3/7] Add PAC addr configure doc --- README-en.md | 2 ++ README.md | 2 ++ 2 files changed, 4 insertions(+) diff --git a/README-en.md b/README-en.md index 32b5b161..5bc017a1 100644 --- a/README-en.md +++ b/README-en.md @@ -30,6 +30,8 @@ Modify configuration file `~/.cow/rc` (OS X or Linux) or `rc.txt` (Windows). A s # Line starting with # is comment and will be ignored # Local proxy listen address + # If cow is deployed behind Loadbalancer, you should specified PAC address(eg. foo.bar.com) like this + # listen = http://127.0.0.1:7777 foo.bar.com:7777 listen = http://127.0.0.1:7777 # SOCKS5 parent proxy diff --git a/README.md b/README.md index faf3c84c..cea7fb52 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,8 @@ COW 的设计目标是自动化,理想情况下用户无需关心哪些网站 # 配置 HTTP 和 HTTPS 代理时请填入该地址 # 若配置代理时有对所有协议使用该代理的选项,且你不清楚此选项的含义,请勾选 # 或者在自动代理配置中填入 http://127.0.0.1:7777/pac + # 如果 cow 部署在负载均衡后面, 需要自定义 PAC 地址(例如: foo.bar.com)如下 + # listen = http://127.0.0.1:7777 foo.bar.com:7777 listen = http://127.0.0.1:7777 # SOCKS5 二级代理 From 1ae326cd43922bcad23fed29b213baac14fdd7c6 Mon Sep 17 00:00:00 2001 From: Jinqiu Yu Date: Mon, 29 Apr 2019 11:54:01 +0800 Subject: [PATCH 4/7] change error hint --- error.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/error.go b/error.go index fad75c75..ff0f0dad 100644 --- a/error.go +++ b/error.go @@ -31,8 +31,7 @@ func init() {

{{.H1}}

{{.Msg}}
- Generated by COW ` + version + `
- Host ` + hostName + `
+ 你电脑经过了代理, 如果是非预期记得关闭代理(系统, 终端等)设置
{{.T}} From 39d6a92bdd5bd6b2f1385b2aadc2ade07e716115 Mon Sep 17 00:00:00 2001 From: Jinqiu Yu Date: Mon, 29 Apr 2019 14:00:25 +0800 Subject: [PATCH 5/7] specified charset --- error.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/error.go b/error.go index ff0f0dad..efbe88fd 100644 --- a/error.go +++ b/error.go @@ -13,7 +13,7 @@ var headRawTmpl = "HTTP/1.1 {{.CodeReason}}\r\n" + "Connection: keep-alive\r\n" + "Cache-Control: no-cache\r\n" + "Pragma: no-cache\r\n" + - "Content-Type: text/html\r\n" + + "Content-Type: text/html;charset=utf-8\r\n" + "Content-Length: {{.Length}}\r\n" var errPageTmpl, headTmpl *template.Template @@ -32,6 +32,7 @@ func init() { {{.Msg}}
你电脑经过了代理, 如果是非预期记得关闭代理(系统, 终端等)设置
+ Host ` + hostName + `
{{.T}} From 2a5da26451e016afc26376da62e5c1997585bc63 Mon Sep 17 00:00:00 2001 From: Jinqiu Yu Date: Thu, 2 May 2019 11:53:00 +0800 Subject: [PATCH 6/7] add customized path --- proxy.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/proxy.go b/proxy.go index f5fe7ba3..1daf9aa8 100644 --- a/proxy.go +++ b/proxy.go @@ -345,7 +345,7 @@ func isSelfRequest(r *Request) bool { // But if client PAC setting is using cow server's DNS name, we can't // decide if the request is for cow itself (need reverse lookup). // So if request path seems like getting PAC, simply return true. - if r.URL.Path == "/pac" || strings.HasPrefix(r.URL.Path, "/pac?") { + if r.URL.Path == "/pac" || r.URL.Path == "/proxy.pac" || strings.HasPrefix(r.URL.Path, "/pac?") { return true } r.URL.ParseHostPort(r.Header.Host) @@ -363,7 +363,7 @@ func (c *clientConn) serveSelfURL(r *Request) (err error) { if r.Method != "GET" { goto end } - if r.URL.Path == "/pac" || strings.HasPrefix(r.URL.Path, "/pac?") { + if r.URL.Path == "/pac" || r.URL.Path == "/proxy.pac" || strings.HasPrefix(r.URL.Path, "/pac?") { sendPAC(c) // PAC header contains connection close, send non nil error to close // client connection. From 770db3f6762030a979cd7665369d1e04d5d7db03 Mon Sep 17 00:00:00 2001 From: yujinqiu Date: Thu, 24 Jun 2021 12:42:03 +0800 Subject: [PATCH 7/7] support go module --- go.mod | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 go.mod diff --git a/go.mod b/go.mod new file mode 100644 index 00000000..115eec30 --- /dev/null +++ b/go.mod @@ -0,0 +1,12 @@ +module github.com/yujinqiu/cow + +go 1.15 + +require ( + github.com/aead/chacha20 v0.0.0-20180709150244-8b13a72661da // indirect + github.com/cyfdecyf/bufio v0.0.0-20130801052708-9601756e2a6b + github.com/cyfdecyf/color v0.0.0-20130827105946-31d518c963d2 + github.com/cyfdecyf/leakybuf v0.0.0-20140618011800-ffae040843be + github.com/shadowsocks/shadowsocks-go v0.0.0-20200409064450-3e585ff90601 + golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e // indirect +)