Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add websocket scheme support to HttpEnvironmentProxy.cs #32302

Merged
merged 1 commit into from
Feb 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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