Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to make a middle proxy that forwards to multiple different end proxies? #429

Open
vedantroy opened this issue Mar 8, 2021 · 3 comments

Comments

@vedantroy
Copy link

vedantroy commented Mar 8, 2021

I see that this example shows how to use an upstream proxy.

I'm wondering how to use multiple upstream proxies. It seems like I could have middleProxy.Tr.Proxy return different proxy URLs based on some round robin strategy.

But, I'm wondering what to do with the ConnectDial field. It seems like it supports a single upstream proxy at a time.

I'm also wondering if it is possible to remove an upstream proxy.

My use case is that I have an auto-scaling group of spot instances that are all running tinyproxy. New instances could potentially be added at anytime & old instances could be removed since spot instances can be arbitrarily terminated.

Update: Nevermind, it seems like ConnectDial is a function that just needs to return a network connection, so I can use round robin there to connect to the different proxy servers. But, I am wondering how tr.Proxy interacts with ConnectDial. I am also wondering whether the OnRequest().HandleConnect method is relevant to making a middle proxy.

@aakarim
Copy link

aakarim commented Mar 13, 2021

You can use middleProxy.Tr.Proxy, in your case, to do what you said. Return a *url.URL to the upstream Proxy. I have a similar use case and I'm doing this to great effect. I use a round robin strategy too.

I also have a question about the CONNECT, though - Can you use MITM and ConnectDial at the same time? If you don't use ConnectDial it will use the middleProxy to negotiate TLS with the server. However, I want to use the upstream proxies, as you do. My question is, can you still use MITM to manipulate the packets on the middleProxy, before it gets to the upstream proxy, without using the middleproxy as the one that negotiates TLS?

@mtatarau90
Copy link

mtatarau90 commented Jun 3, 2021

gServer := goproxy.NewProxyHttpServer()
gServer.OnRequest().DoFunc(func(req *http.Request, ctx *goproxy.ProxyCtx) (*http.Request, *http.Response) {
	proxy, _ := url.Parse("http://user:[email protected]:port")
	gServer.Tr = &http.Transport{
		Proxy:           http.ProxyURL(proxy),
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	}
})

@xzycn
Copy link

xzycn commented May 3, 2022

@mtatarau90 how to handle the concurrency problem?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants