1// Package ieproxy is a utility to retrieve the proxy parameters (especially of Internet Explorer on windows) 2// 3// On windows, it gathers the parameters from the registry (regedit), while it uses env variable on other platforms 4package ieproxy 5 6import "os" 7 8// ProxyConf gathers the configuration for proxy 9type ProxyConf struct { 10 Static StaticProxyConf // static configuration 11 Automatic ProxyScriptConf // script configuration 12} 13 14// StaticProxyConf contains the configuration for static proxy 15type StaticProxyConf struct { 16 // Is the proxy active? 17 Active bool 18 // Proxy address for each scheme (http, https) 19 // "" (empty string) is the fallback proxy 20 Protocols map[string]string 21 // Addresses not to be browsed via the proxy (comma-separated, linux-like) 22 NoProxy string 23} 24 25// ProxyScriptConf contains the configuration for automatic proxy 26type ProxyScriptConf struct { 27 // Is the proxy active? 28 Active bool 29 // PreConfiguredURL of the .pac file. 30 // If this is empty and Active is true, auto-configuration should be assumed. 31 PreConfiguredURL string 32} 33 34// GetConf retrieves the proxy configuration from the Windows Regedit 35func GetConf() ProxyConf { 36 return getConf() 37} 38 39// OverrideEnvWithStaticProxy writes new values to the 40// `http_proxy`, `https_proxy` and `no_proxy` environment variables. 41// The values are taken from the Windows Regedit (should be called in `init()` function - see example) 42func OverrideEnvWithStaticProxy() { 43 overrideEnvWithStaticProxy(GetConf(), os.Setenv) 44} 45 46// FindProxyForURL computes the proxy for a given URL according to the pac file 47func (psc *ProxyScriptConf) FindProxyForURL(URL string) string { 48 return psc.findProxyForURL(URL) 49} 50 51type envSetter func(string, string) error 52