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 二级代理 diff --git a/error.go b/error.go index fad75c75..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 @@ -31,7 +31,7 @@ func init() {

{{.H1}}

{{.Msg}}
- Generated by COW ` + version + `
+ 你电脑经过了代理, 如果是非预期记得关闭代理(系统, 终端等)设置
Host ` + hostName + `
{{.T}} 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 +) diff --git a/proxy.go b/proxy.go index 601ac65e..1daf9aa8 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.addr) + } } info.Printf("COW %s listen http %s, PAC url %s\n", version, hp.addr, pacURL) @@ -343,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) @@ -361,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.