private static IWebProxy GetProxy() { if (webProxy == null) { // Uses HttpEnvironmentProxy class to mimic .NET Core behavior HttpEnvironmentProxy.TryCreate(out webProxy); } return(webProxy); }
private static IWebProxy GetProxy() { // Ensure TLS 1.2 is enabled if (!ServicePointManager.SecurityProtocol.HasFlag(SecurityProtocolType.Tls12)) { ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls12; } if (webProxy == null) { // Uses HttpEnvironmentProxy class to mimic .NET Core behavior HttpEnvironmentProxy.TryCreate(out webProxy); } return(webProxy); }
public static bool TryCreate(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); }