goproxy
goproxy copied to clipboard
Transport proxy is not used in case of https
I am trying to workaround https://github.com/chromedp/chromedp/issues/190 by launching a goproxy server that would forward requests to another proxy.
pxy := goproxy.NewProxyHttpServer()
pxy.Tr.Proxy = http.ProxyURL(proxyurl)
go func() {
err := http.ListenAndServe("localhost:9000", pxy)
h.LogOnError(err)
}()
Requests to http are OK but https are not using the proxy. Is it possible to add a proxy to the hijacked connection?
yes you have to create a custom connectDial: https://github.com/elazarl/goproxy/blob/aa519ddbe484d5dddfd1a4056f90aa2b6cbc99cf/proxy.go#L31
Thanks @azak-azkaran I will take a look. It would be great if you can provide a full example if you have the time.
@azak-azkaran The dialer you mentioned does not provide any proxy authentication, it is just a network dailer. Am I missing something?
The goproxy Library comes with a custom dialer for proxy connections:
Please take a look at:
https://github.com/elazarl/goproxy/blob/aa519ddbe484d5dddfd1a4056f90aa2b6cbc99cf/https.go#L325
Or:
https://github.com/elazarl/goproxy/blob/aa519ddbe484d5dddfd1a4056f90aa2b6cbc99cf/https.go#L321
That worked for a proxy without authintication but failed when there is a username and password in the proxy URL:
pxy := goproxy.NewProxyHttpServer()
pxy.ConnectDial = pxy.NewConnectDialToProxy("http://user:[email protected]:8000")
http.ListenAndServe("localhost:9000", pxy)
also with the handler
pxy.ConnectDial = pxy.NewConnectDialToProxyWithHandler("http://example.com:8000", func(r *http.Request) {
basicAuth := "Basic " + base64.StdEncoding.EncodeToString([]byte("user:pass"))
r.Header.Add("Proxy-Authorization", basicAuth) //causes 502 error
})
pxy.Tr.Proxy = http.ProxyURL(h.ParseUrl("http://user:[email protected]:8000"))
I also noticed the dialer is handling https connections while the transport proxy is handling http only so we need to add both anyways. Any other way to do that? I would appreciate a working example.