Fixes #32230 (#32302)
authorBrian Walker <daddyman@users.noreply.github.com>
Mon, 24 Feb 2020 18:28:05 +0000 (12:28 -0600)
committerGitHub <noreply@github.com>
Mon, 24 Feb 2020 18:28:05 +0000 (10:28 -0800)
Use insecure proxy (http_proxy) for schemes http and ws
Use secure proxy (https_proxy) to schemes https and wss

src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpEnvironmentProxy.cs
src/libraries/System.Net.Http/tests/UnitTests/HttpEnvironmentProxyTest.cs

index a2150ed..43268fe 100644 (file)
@@ -266,7 +266,7 @@ namespace System.Net.Http
         /// </summary>
         public Uri GetProxy(Uri uri)
         {
-            return uri.Scheme == Uri.UriSchemeHttp ? _httpProxyUri : _httpsProxyUri;
+            return HttpUtilities.IsSupportedNonSecureScheme(uri.Scheme) ? _httpProxyUri : _httpsProxyUri;
         }
 
         /// <summary>
index dd9607e..e168d3f 100644 (file)
@@ -16,6 +16,8 @@ namespace System.Net.Http.Tests
         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.
@@ -61,6 +63,11 @@ namespace System.Net.Http.Tests
                 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);
@@ -72,6 +79,11 @@ namespace System.Net.Http.Tests
                 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");
@@ -83,6 +95,11 @@ namespace System.Net.Http.Tests
                 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");
@@ -91,6 +108,9 @@ namespace System.Net.Http.Tests
                 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));
@@ -100,6 +120,11 @@ namespace System.Net.Http.Tests
                 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();
         }