public static bool TryCreate([NotNullWhen(true)] out IWebProxy?proxy) { // Get environment variables. Protocol specific take precedence over // general all_*, lower case variable has precedence over upper case. // Note that curl uses HTTPS_PROXY but not HTTP_PROXY. Uri?httpProxy = GetUriFromString(Environment.GetEnvironmentVariable(EnvHttpProxyLC)); if (httpProxy == null && Environment.GetEnvironmentVariable(EnvCGI) == null) { httpProxy = GetUriFromString(Environment.GetEnvironmentVariable(EnvHttpProxyUC)); } Uri?httpsProxy = GetUriFromString(Environment.GetEnvironmentVariable(EnvHttpsProxyLC)) ?? GetUriFromString(Environment.GetEnvironmentVariable(EnvHttpsProxyUC)); if (httpProxy == null || httpsProxy == null) { Uri?allProxy = GetUriFromString(Environment.GetEnvironmentVariable(EnvAllProxyLC)) ?? GetUriFromString(Environment.GetEnvironmentVariable(EnvAllProxyUC)); if (httpProxy == null) { httpProxy = allProxy; } if (httpsProxy == null) { httpsProxy = allProxy; } } // Do not instantiate if nothing is set. // Caller may pick some other proxy type. if (httpProxy == null && httpsProxy == null) { proxy = null; return(false); } string?noProxy = Environment.GetEnvironmentVariable(EnvNoProxyLC) ?? Environment.GetEnvironmentVariable(EnvNoProxyUC); proxy = new HttpEnvironmentProxy(httpProxy, httpsProxy, noProxy); return(true); }
public static bool TryCreate([NotNullWhen(true)] out IWebProxy?proxy) { // Get environment variables. Protocol specific take precedence over // general all_*. On Windows, environment variables are case insensitive. Uri?httpProxy = null; if (Environment.GetEnvironmentVariable(EnvCGI) == null) { httpProxy = GetUriFromString(Environment.GetEnvironmentVariable(EnvHttpProxyUC)); } Uri?httpsProxy = GetUriFromString(Environment.GetEnvironmentVariable(EnvHttpsProxyUC)); if (httpProxy == null || httpsProxy == null) { Uri?allProxy = GetUriFromString(Environment.GetEnvironmentVariable(EnvAllProxyUC)); if (httpProxy == null) { httpProxy = allProxy; } if (httpsProxy == null) { httpsProxy = allProxy; } } // Do not instantiate if nothing is set. // Caller may pick some other proxy type. if (httpProxy == null && httpsProxy == null) { proxy = null; return(false); } string?noProxy = Environment.GetEnvironmentVariable(EnvNoProxyUC); proxy = new HttpEnvironmentProxy(httpProxy, httpsProxy, noProxy); return(true); }
public static bool TryCreate(out IWebProxy proxy) { // Get environmental variables. Protocol specific take precedence over // general all_*, lower case variable has precedence over upper case. // Note that curl uses HTTPS_PROXY but not HTTP_PROXY. // For http, only http_proxy and generic variables are used. Uri httpProxy = GetUriFromString(Environment.GetEnvironmentVariable(EnvHttpProxyLC)); Uri httpsProxy = GetUriFromString(Environment.GetEnvironmentVariable(EnvHttpsProxyLC)) ?? GetUriFromString(Environment.GetEnvironmentVariable(EnvHttpsProxyUC)); if (httpProxy == null || httpsProxy == null) { Uri allProxy = GetUriFromString(Environment.GetEnvironmentVariable(EnvAllProxyLC)) ?? GetUriFromString(Environment.GetEnvironmentVariable(EnvAllProxyUC)); if (httpProxy == null) { httpProxy = allProxy; } if (httpsProxy == null) { httpsProxy = allProxy; } } // Do not instantiate if nothing is set. // Caller may pick some other proxy type. if (httpProxy == null && httpsProxy == null) { proxy = null; return(false); } proxy = new HttpEnvironmentProxy(httpProxy, httpsProxy, Environment.GetEnvironmentVariable(EnvNoProxyLC)); return(true); }