Skip to content

Commit

Permalink
Fixes #32230 (#32302)
Browse files Browse the repository at this point in the history
Use insecure proxy (http_proxy) for schemes http and ws
Use secure proxy (https_proxy) to schemes https and wss
  • Loading branch information
daddyman authored Feb 24, 2020
1 parent b93b498 commit 67e9a10
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ private bool IsMatchInBypassList(Uri input)
/// </summary>
public Uri GetProxy(Uri uri)
{
return uri.Scheme == Uri.UriSchemeHttp ? _httpProxyUri : _httpsProxyUri;
return HttpUtilities.IsSupportedNonSecureScheme(uri.Scheme) ? _httpProxyUri : _httpsProxyUri;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ public class HttpEnvironmentProxyTest
private readonly ITestOutputHelper _output;
private static readonly Uri fooHttp = new Uri("http://foo.com");
private static readonly Uri fooHttps = new Uri("https://foo.com");
private static readonly Uri fooWs = new Uri("ws://foo.com");
private static readonly Uri fooWss = new Uri("wss://foo.com");

// This will clean specific environmental variables
// to be sure they do not interfere with the test.
Expand Down Expand Up @@ -61,6 +63,11 @@ public void HttpProxy_EnvironmentProxy_Loaded()
u = p.GetProxy(fooHttps);
Assert.True(u != null && u.Host == "1.1.1.1");

u = p.GetProxy(fooWs);
Assert.True(u != null && u.Host == "1.1.1.1");
u = p.GetProxy(fooWss);
Assert.True(u != null && u.Host == "1.1.1.1");

Environment.SetEnvironmentVariable("http_proxy", "http://1.1.1.2:3001");
Assert.True(HttpEnvironmentProxy.TryCreate(out p));
Assert.NotNull(p);
Expand All @@ -72,6 +79,11 @@ public void HttpProxy_EnvironmentProxy_Loaded()
u = p.GetProxy(fooHttps);
Assert.True(u != null && u.Host == "1.1.1.1" && u.Port == 3000);

u = p.GetProxy(fooWs);
Assert.True(u != null && u.Host == "1.1.1.2" && u.Port == 3001);
u = p.GetProxy(fooWss);
Assert.True(u != null && u.Host == "1.1.1.1" && u.Port == 3000);

// Set https to invalid strings and use only IP & port for http.
Environment.SetEnvironmentVariable("http_proxy", "1.1.1.3:3003");
Environment.SetEnvironmentVariable("https_proxy", "ab!cd");
Expand All @@ -83,6 +95,11 @@ public void HttpProxy_EnvironmentProxy_Loaded()
u = p.GetProxy(fooHttps);
Assert.True(u != null && u.Host == "1.1.1.1" && u.Port == 3000);

u = p.GetProxy(fooWs);
Assert.True(u != null && u.Host == "1.1.1.3" && u.Port == 3003);
u = p.GetProxy(fooWss);
Assert.True(u != null && u.Host == "1.1.1.1" && u.Port == 3000);

// Try valid URI with unsupported protocol. It will be ignored
// to mimic curl behavior.
Environment.SetEnvironmentVariable("https_proxy", "socks5://1.1.1.4:3004");
Expand All @@ -91,6 +108,9 @@ public void HttpProxy_EnvironmentProxy_Loaded()
u = p.GetProxy(fooHttps);
Assert.True(u != null && u.Host == "1.1.1.1" && u.Port == 3000);

u = p.GetProxy(fooWss);
Assert.True(u != null && u.Host == "1.1.1.1" && u.Port == 3000);

// Set https to valid URI but different from http.
Environment.SetEnvironmentVariable("https_proxy", "http://1.1.1.5:3005");
Assert.True(HttpEnvironmentProxy.TryCreate(out p));
Expand All @@ -100,6 +120,11 @@ public void HttpProxy_EnvironmentProxy_Loaded()
Assert.True(u != null && u.Host == "1.1.1.3" && u.Port == 3003);
u = p.GetProxy(fooHttps);
Assert.True(u != null && u.Host == "1.1.1.5" && u.Port == 3005);

u = p.GetProxy(fooWs);
Assert.True(u != null && u.Host == "1.1.1.3" && u.Port == 3003);
u = p.GetProxy(fooWss);
Assert.True(u != null && u.Host == "1.1.1.5" && u.Port == 3005);
}).Dispose();
}

Expand Down

0 comments on commit 67e9a10

Please sign in to comment.