add back parsing for simple configuration (dotnet/corefx#31314)
authorTomas Weinfurt <tweinfurt@yahoo.com>
Tue, 24 Jul 2018 18:10:18 +0000 (11:10 -0700)
committerGitHub <noreply@github.com>
Tue, 24 Jul 2018 18:10:18 +0000 (11:10 -0700)
* add back simplified proxy configuration
* add tracing
* feedback from review

Commit migrated from https://github.com/dotnet/corefx/commit/2c5f29064929d4f1c60be7c5c301a488dfab02c4

src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpSystemProxy.cs
src/libraries/System.Net.Http/tests/UnitTests/HttpSystemProxyTest.cs

index 4cf0ab4..8fab9bc 100644 (file)
@@ -66,7 +66,13 @@ namespace System.Net.Http
 
             if (proxyHelper.ManualSettingsOnly)
             {
+                if (NetEventSource.IsEnabled) NetEventSource.Info(proxyHelper, $"ManualSettingsUsed, {proxyHelper.Proxy}");
                 ParseProxyConfig(proxyHelper.Proxy, out _insecureProxyUri, out _secureProxyUri);
+                if (_insecureProxyUri == null && _secureProxyUri == null)
+                {
+                    // If advanced parsing by protocol fails, fall-back to simplified parsing.
+                    _insecureProxyUri = _secureProxyUri = GetUriFromString(proxyHelper.Proxy);
+                }
 
                 if (!string.IsNullOrWhiteSpace(proxyHelper.ProxyBypass))
                 {
index 756eae3..74e995e 100644 (file)
@@ -65,6 +65,29 @@ namespace System.Net.Http.Tests
         }
 
         [Theory]
+        [InlineData("localhost:1234", "http://localhost:1234/")]
+        [InlineData("123.123.123.123", "http://123.123.123.123/")]
+        public void HttpProxy_SystemProxy_Loaded(string rawProxyString, string expectedUri)
+        {
+            RemoteInvoke((proxyString, expectedString) =>
+            {
+                IWebProxy p;
+
+                FakeRegistry.Reset();
+
+                FakeRegistry.WinInetProxySettings.Proxy = proxyString;
+                WinInetProxyHelper proxyHelper = new WinInetProxyHelper();
+
+                Assert.True(HttpSystemProxy.TryCreate(out p));
+                Assert.NotNull(p);
+                Assert.Equal(expectedString, p.GetProxy(new Uri(fooHttp)).ToString());
+                Assert.Equal(expectedString, p.GetProxy(new Uri(fooHttps)).ToString());
+
+                return SuccessExitCode;
+            }, rawProxyString, expectedUri).Dispose();
+        }
+
+        [Theory]
         [InlineData("http://localhost/", true)]
         [InlineData("http://127.0.0.1/", true)]
         [InlineData("http://128.0.0.1/", false)]
@@ -144,7 +167,6 @@ namespace System.Net.Http.Tests
         [InlineData("http://;")]
         [InlineData("http=;")]
         [InlineData("  ;  ")]
-        [InlineData("proxy.contoso.com")]
         public void HttpProxy_InvalidSystemProxy_Null(string rawProxyString)
         {
             RemoteInvoke((proxyString) =>