goproxy icon indicating copy to clipboard operation
goproxy copied to clipboard

cascade example Tr.Proxy function not being invoked..

Open muranant opened this issue 4 years ago • 1 comments

This is in reference to the cascade example: https://github.com/elazarl/goproxy/blob/master/examples/cascadeproxy/main.go

I was trying to check when the following function for Tr.Proxy() was being invoked. Adding some debug statements in that function does not seem to invoke this code.

Also, commenting out all of the code below here, does not seem to change anything. The proxy request still goes through.

Couple of questions:

  • When and how should Tr.Proxy used?
  • As the code is working without the below code, is there an override that is happening for Tr.Proxy
  • Same for the Connect.Dial. Why did it work when it was commented out?
	middleProxy.Tr.Proxy = func(req *http.Request) (*url.URL, error) {
		return url.Parse("http://localhost:8082")
	}
	connectReqHandler := func(req *http.Request) {
		SetBasicAuth(username, password, req)
	}
	middleProxy.ConnectDial = middleProxy.NewConnectDialToProxyWithHandler("http://localhost:8082", connectReqHandler)
	middleProxy.OnRequest().Do(goproxy.FuncReqHandler(func(req *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
		SetBasicAuth(username, password, req)
		return req, nil
	}))

muranant avatar Jul 16 '21 22:07 muranant

Hi, there has a comment about the method ConnectDial:

ConnectDial will be used to create TCP connections for CONNECT requests So, you should visit destination through https instead http :)

xzycn avatar Apr 28 '22 23:04 xzycn