Blame vendor/github.com/mattn/go-ieproxy/proxyMiddleman_windows.go

Packit 63bb0d
package ieproxy
Packit 63bb0d
Packit 63bb0d
import (
Packit 63bb0d
	"net/http"
Packit 63bb0d
	"net/url"
Packit 63bb0d
Packit 63bb0d
	"golang.org/x/net/http/httpproxy"
Packit 63bb0d
)
Packit 63bb0d
Packit 63bb0d
func proxyMiddleman() func(req *http.Request) (i *url.URL, e error) {
Packit 63bb0d
	// Get the proxy configuration
Packit 63bb0d
	conf := GetConf()
Packit 63bb0d
	envcfg := httpproxy.FromEnvironment()
Packit 63bb0d
Packit 63bb0d
	if envcfg.HTTPProxy != "" || envcfg.HTTPSProxy != "" {
Packit 63bb0d
		// If the user manually specifies environment variables, prefer those over the Windows config.
Packit 63bb0d
		return http.ProxyFromEnvironment
Packit 63bb0d
	} else if conf.Automatic.Active {
Packit 63bb0d
		// If automatic proxy obtaining is specified
Packit 63bb0d
		return func(req *http.Request) (i *url.URL, e error) {
Packit 63bb0d
			host := conf.Automatic.FindProxyForURL(req.URL.String())
Packit 63bb0d
			if host == "" {
Packit 63bb0d
				return nil, nil
Packit 63bb0d
			}
Packit 63bb0d
			return &url.URL{Host: host}, nil
Packit 63bb0d
		}
Packit 63bb0d
	} else if conf.Static.Active {
Packit 63bb0d
		// If static proxy obtaining is specified
Packit 63bb0d
		prox := httpproxy.Config{
Packit 63bb0d
			HTTPSProxy: mapFallback("https", "", conf.Static.Protocols),
Packit 63bb0d
			HTTPProxy:  mapFallback("http", "", conf.Static.Protocols),
Packit 63bb0d
			NoProxy:    conf.Static.NoProxy,
Packit 63bb0d
		}
Packit 63bb0d
Packit 63bb0d
		return func(req *http.Request) (i *url.URL, e error) {
Packit 63bb0d
			return prox.ProxyFunc()(req.URL)
Packit 63bb0d
		}
Packit 63bb0d
	} else {
Packit 63bb0d
		// Final fallthrough case; use the environment variables.
Packit 63bb0d
		return http.ProxyFromEnvironment
Packit 63bb0d
	}
Packit 63bb0d
}
Packit 63bb0d
Packit 63bb0d
// Return oKey or fbKey if oKey doesn't exist in the map.
Packit 63bb0d
func mapFallback(oKey, fbKey string, m map[string]string) string {
Packit 63bb0d
	if v, ok := m[oKey]; ok {
Packit 63bb0d
		return v
Packit 63bb0d
	} else {
Packit 63bb0d
		return m[fbKey]
Packit 63bb0d
	}
Packit 63bb0d
}