I'm trying write rotating proxy on golang. there are no problems when proxying http: copied the client's request and forwarded it. But when I want to forward https - I can not read the request body, since it is encrypted. I learned that with the help of HTTP CONNECT, it is possible to create the tcp tunnel, but I cannot get the third-party proxy server to work. My scheme of work should be like this: 1) client -> 2) my proxy server -> 3) third-party proxy server -> 4) the site that the client wants but for now I'm stuck between 2 and 3 Can anyone help me?
i get this code as example https://github.com/hkwi/https_tproxy/blob/master/main.go
func handle(con net.Conn) {
defer con.Close()
req := &http.Request{
Method: "CONNECT",
Host: con.LocalAddr().String(),
URL: &url.URL{},
}
conOut, err := net.DialTimeout("tcp", "EXTERNALPROXYIP:8080", 2*time.Second)
if err != nil {
log.Printf("proxy error %v", err)
}
defer conOut.Close()
if err := req.WriteProxy(conOut); err != nil {
log.Printf("proxy error %v", err)
} else if res, err := http.ReadResponse(bufio.NewReader(conOut), req); err != nil {
log.Printf("proxy error %v", err)
} else if res.StatusCode != 200 {
log.Printf("proxy error %v", err)
} else {
sent := make(chan bool)
go func() {
_, err := io.Copy(conOut, con)
if err != nil {
log.Printf("proxy error %v", err)
}
close(sent)
}()
_, err := io.Copy(con, res.Body)
if err != nil {
log.Printf("proxy error %v", err) ------> ERROR
}
_ = <-sent
}
}
i have issue proxy error invalid byte in chunk length