goproxy icon indicating copy to clipboard operation
goproxy copied to clipboard

Transport proxy is not used in case of https

Open gadelkareem opened this issue 5 years ago • 6 comments

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?

gadelkareem avatar Oct 30 '19 22:10 gadelkareem

yes you have to create a custom connectDial: https://github.com/elazarl/goproxy/blob/aa519ddbe484d5dddfd1a4056f90aa2b6cbc99cf/proxy.go#L31

azak-azkaran avatar Nov 27 '19 08:11 azak-azkaran

Thanks @azak-azkaran I will take a look. It would be great if you can provide a full example if you have the time.

gadelkareem avatar Dec 01 '19 12:12 gadelkareem

@azak-azkaran The dialer you mentioned does not provide any proxy authentication, it is just a network dailer. Am I missing something?

gadelkareem avatar Dec 08 '19 12:12 gadelkareem

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

azak-azkaran avatar Dec 09 '19 08:12 azak-azkaran

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)

gadelkareem avatar Dec 21 '19 16:12 gadelkareem

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.

gadelkareem avatar Dec 21 '19 16:12 gadelkareem