I'm trying to get a better idea of how Go's HTTP Transport "Proxy" field works. It's a func(*Request) (*url.URL, error)
with the following description:
Proxy specifies a function to return a proxy for a given Request.
This suggests that it's intended to be able to dynamically select a proxy for a given request, meaning that each request could use a different proxy.
What I'm trying to understand is how this interacts with the concept of keeping HTTP connections open and re-using them.
- Is it the case that if multiple HTTP Requests use the same proxy, the transport will keep a connection to that proxy open and re-use it?
- Can a connection to the final destination be kept open and re-used across an HTTP proxy?
- If I have a connection to the final destination, but my Proxy function returns a different proxy URL for a subsequent connection to the same host, will it always need to open a new connection to that host (since the connection is now going over a different proxy)?
- If the answer to the above is "yes", then is there a best practice for dynamic proxy selection (e.g. always returning the same proxy URL for a given host)?
- Are there any differences in the answers to the above questions between HTTP, HTTPS, and SOCKS5 proxies?