From 2813e80a98a9af76e67340a7f36187e11317798e Mon Sep 17 00:00:00 2001 From: nadoo <287492+nadoo@users.noreply.github.com> Date: Wed, 21 Nov 2018 20:28:46 +0800 Subject: [PATCH] http: fix #76 --- .../rules.d/office.rule | 3 ++- proxy/http/http.go | 23 ++++++++----------- proxy/mixed/mixed.go | 3 +-- proxy/vmess/client.go | 5 +++- 4 files changed, 17 insertions(+), 17 deletions(-) diff --git a/config/examples/9.transparent_proxy_without_dnsmasq/rules.d/office.rule b/config/examples/9.transparent_proxy_without_dnsmasq/rules.d/office.rule index f6db0fb..634e88e 100644 --- a/config/examples/9.transparent_proxy_without_dnsmasq/rules.d/office.rule +++ b/config/examples/9.transparent_proxy_without_dnsmasq/rules.d/office.rule @@ -16,7 +16,8 @@ checkduration=30 dnsserver=208.67.222.222:53 # specify destinations -#include=office.list +include=office.list + domain=example1.com domain=example2.com # matches ip diff --git a/proxy/http/http.go b/proxy/http/http.go index c35bf78..871a76a 100644 --- a/proxy/http/http.go +++ b/proxy/http/http.go @@ -162,8 +162,8 @@ func (s *HTTP) Serve(c net.Conn) { uri := u.String() var reqBuf bytes.Buffer - writeFirstLine(method, uri, proto, &reqBuf) - writeHeaders(reqHeader, &reqBuf) + writeFirstLine(&reqBuf, method, uri, proto) + writeHeaders(&reqBuf, reqHeader) // send request to remote server rc.Write(reqBuf.Bytes()) @@ -194,8 +194,8 @@ func (s *HTTP) Serve(c net.Conn) { respHeader.Set("Connection", "close") var respBuf bytes.Buffer - writeFirstLine(proto, code, status, &respBuf) - writeHeaders(respHeader, &respBuf) + writeFirstLine(&respBuf, proto, code, status) + writeHeaders(&respBuf, respHeader) log.F("[http] %s <-> %s", c.RemoteAddr(), tgt) c.Write(respBuf.Bytes()) @@ -309,7 +309,7 @@ func cleanHeaders(header textproto.MIMEHeader) { header.Del("Upgrade") } -func writeFirstLine(s1, s2, s3 string, buf *bytes.Buffer) { +func writeFirstLine(buf *bytes.Buffer, s1, s2, s3 string) { buf.Write([]byte(s1)) buf.Write([]byte(" ")) buf.Write([]byte(s2)) @@ -318,17 +318,14 @@ func writeFirstLine(s1, s2, s3 string, buf *bytes.Buffer) { buf.Write([]byte("\r\n")) } -func writeHeaders(header textproto.MIMEHeader, buf *bytes.Buffer) { +func writeHeaders(buf *bytes.Buffer, header textproto.MIMEHeader) { for key, values := range header { - buf.Write([]byte(key)) - buf.Write([]byte(": ")) - for k, v := range values { + for _, v := range values { + buf.Write([]byte(key)) + buf.Write([]byte(": ")) buf.Write([]byte(v)) - if k > 0 { - buf.Write([]byte(" ")) - } + buf.Write([]byte("\r\n")) } - buf.Write([]byte("\r\n")) } //header ended diff --git a/proxy/mixed/mixed.go b/proxy/mixed/mixed.go index 07bfad8..a809340 100644 --- a/proxy/mixed/mixed.go +++ b/proxy/mixed/mixed.go @@ -75,9 +75,8 @@ func (p *MixedProxy) ListenAndServe(c net.Conn) { if c == nil { go p.socks5.ListenAndServeUDP() - l, err := net.Listen("tcp", p.addr) - //l, err := net.Listen("tcp", p.addr) + l, err := net.Listen("tcp", p.addr) if err != nil { log.F("[mixed] failed to listen on %s: %v", p.addr, err) return diff --git a/proxy/vmess/client.go b/proxy/vmess/client.go index 72dbd3c..5bad7d7 100644 --- a/proxy/vmess/client.go +++ b/proxy/vmess/client.go @@ -207,10 +207,13 @@ func (c *Conn) DecodeRespHeader() error { } stream := cipher.NewCFBDecrypter(block, c.respBodyIV[:]) + buf := make([]byte, 4) - if _, err := io.ReadFull(c.Conn, buf); err != nil { + _, err = io.ReadFull(c.Conn, buf) + if err != nil { return err } + stream.XORKeyStream(buf, buf) if buf[0] != c.reqRespV {