http: keep proxy-connection when connect to upstream http proxy. #42

This commit is contained in:
nadoo 2018-07-31 20:25:39 +08:00
parent 4781e7b472
commit a2a67df771

View File

@ -231,16 +231,19 @@ func (s *HTTP) Dial(network, addr string) (net.Conn, error) {
c.SetKeepAlive(true) c.SetKeepAlive(true)
} }
rc.Write([]byte("CONNECT " + addr + " HTTP/1.0\r\n")) var buf bytes.Buffer
rc.Write([]byte("Proxy-Connection: close\r\n"))
buf.Write([]byte("CONNECT " + addr + " HTTP/1.1\r\n"))
buf.Write([]byte("Proxy-Connection: Keep-Alive\r\n"))
if s.user != "" && s.password != "" { if s.user != "" && s.password != "" {
auth := s.user + ":" + s.password auth := s.user + ":" + s.password
rc.Write([]byte("Proxy-Authorization: Basic " + base64.StdEncoding.EncodeToString([]byte(auth)) + "\r\n")) buf.Write([]byte("Proxy-Authorization: Basic " + base64.StdEncoding.EncodeToString([]byte(auth)) + "\r\n"))
} }
//header ended //header ended
rc.Write([]byte("\r\n")) buf.Write([]byte("\r\n"))
rc.Write(buf.Bytes())
respR := bufio.NewReader(rc) respR := bufio.NewReader(rc)
respTP := textproto.NewReader(respR) respTP := textproto.NewReader(respR)