no message
This commit is contained in:
@ -312,14 +312,16 @@ func (s *SPS) OutToTCP(inConn *net.Conn) (err error) {
|
|||||||
//ask parent for connect to target address
|
//ask parent for connect to target address
|
||||||
if *s.cfg.ParentServiceType == "http" {
|
if *s.cfg.ParentServiceType == "http" {
|
||||||
//http parent
|
//http parent
|
||||||
|
isHTTPS:=false
|
||||||
pb := new(bytes.Buffer)
|
pb := new(bytes.Buffer)
|
||||||
if len(forwardBytes) > 0 {
|
if len(forwardBytes) == 0 {
|
||||||
pb.Write(forwardBytes)
|
isHTTPS=true
|
||||||
pb.WriteString("\r\nProxy-Connection: Keep-Alive\r\n")
|
pb.Write([]byte(fmt.Sprintf("CONNECT %s HTTP/1.1", address)))
|
||||||
forwardBytes=nil
|
|
||||||
}else{
|
|
||||||
pb.Write([]byte(fmt.Sprintf("CONNECT %s HTTP/1.1\r\nProxy-Connection: Keep-Alive\r\n", address)))
|
|
||||||
}
|
}
|
||||||
|
pb.WriteString("\r\nProxy-Connection: Keep-Alive\r\n")
|
||||||
|
|
||||||
|
s.log.Printf("before bytes:%s",string(forwardBytes))
|
||||||
|
|
||||||
//Proxy-Authorization:\r\n
|
//Proxy-Authorization:\r\n
|
||||||
u := ""
|
u := ""
|
||||||
if *s.cfg.ParentAuth != "" {
|
if *s.cfg.ParentAuth != "" {
|
||||||
@ -337,7 +339,22 @@ func (s *SPS) OutToTCP(inConn *net.Conn) (err error) {
|
|||||||
if u != "" {
|
if u != "" {
|
||||||
pb.Write([]byte(fmt.Sprintf("Proxy-Authorization:Basic %s\r\n", base64.StdEncoding.EncodeToString([]byte(u)))))
|
pb.Write([]byte(fmt.Sprintf("Proxy-Authorization:Basic %s\r\n", base64.StdEncoding.EncodeToString([]byte(u)))))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if isHTTPS{
|
||||||
pb.Write([]byte("\r\n"))
|
pb.Write([]byte("\r\n"))
|
||||||
|
}else{
|
||||||
|
//do remove some headers with forwardBytes
|
||||||
|
//forwardBytes
|
||||||
|
|
||||||
|
forwardBytes=bytes.Replace(forwardBytes,[]byte("\r\n"),[]byte(pb.Bytes()),1)
|
||||||
|
pb.Reset()
|
||||||
|
pb.Write(forwardBytes)
|
||||||
|
if !bytes.Contains(forwardBytes,[]byte("\r\n\r\n\r\n")){
|
||||||
|
pb.Write([]byte("\r\n\r\n"))
|
||||||
|
}
|
||||||
|
forwardBytes=nil
|
||||||
|
}
|
||||||
|
|
||||||
outConn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
outConn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
_, err = outConn.Write(pb.Bytes())
|
_, err = outConn.Write(pb.Bytes())
|
||||||
outConn.SetDeadline(time.Time{})
|
outConn.SetDeadline(time.Time{})
|
||||||
@ -347,6 +364,11 @@ func (s *SPS) OutToTCP(inConn *net.Conn) (err error) {
|
|||||||
utils.CloseConn(&outConn)
|
utils.CloseConn(&outConn)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s.log.Printf("ishttps:%v",isHTTPS)
|
||||||
|
s.log.Printf("bytes:%s",string(pb.Bytes()))
|
||||||
|
|
||||||
|
if isHTTPS{
|
||||||
reply := make([]byte, 1024)
|
reply := make([]byte, 1024)
|
||||||
outConn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
outConn.SetDeadline(time.Now().Add(time.Millisecond * time.Duration(*s.cfg.Timeout)))
|
||||||
_, err = outConn.Read(reply)
|
_, err = outConn.Read(reply)
|
||||||
@ -358,6 +380,7 @@ func (s *SPS) OutToTCP(inConn *net.Conn) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
//s.log.Printf("reply: %s", string(reply[:n]))
|
//s.log.Printf("reply: %s", string(reply[:n]))
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
s.log.Printf("connect %s", address)
|
s.log.Printf("connect %s", address)
|
||||||
//socks client
|
//socks client
|
||||||
|
|||||||
Reference in New Issue
Block a user