AdguardTeam / gomitmproxy

Simple golang mitm proxy implementation
https://adguard.com/
GNU General Public License v3.0
273 stars 53 forks source link

Feat request: Please allow us to have access to transport config #24

Open tgrushka opened 4 months ago

tgrushka commented 4 months ago

gomitmproxy.NewProxy starts out as follows:


// NewProxy creates a new instance of the Proxy
func NewProxy(config Config) *Proxy {
    proxy := &Proxy{
        Config: config,
        transport: &http.Transport{
            // This forces http.Transport to not upgrade requests to HTTP/2
            // TODO: Remove when HTTP/2 can be supported
            TLSNextProto:          make(map[string]func(string, *tls.Conn) http.RoundTripper),
            Proxy:                 http.ProxyFromEnvironment,
...

The Proxy: http.ProxyFromEnvironment is what affects me specifically. I am using an upstream proxy, and having to os.Setenv... to make it work is very inelegant:

os.Setenv("ALL_PROXY", upstreamProxy)
os.Setenv("HTTP_PROXY", upstreamProxy)
os.Setenv("HTTPS_PROXY", upstreamProxy)
fmt.Println("Upstream Proxy =", upstreamProxy)

Being able to pass this in, perhaps via the Config would be amazing. I would be happy to make a PR, please suggest if can be added to Config (maybe simple/non-breaking) or should be done some other way.

Thank you.

ameshkov commented 3 months ago

Makes sense, thank you!

I'd suggest doing it the following way:

  1. Add an optional ProxyDialer proxy.Dialer field to Config.
  2. When creating the transport check use it OR use http.ProxyFromEnvironment if it's nil. Please explain this logic in the field comment.