From 6191c23ba71581ba19748dceadddf67160666705 Mon Sep 17 00:00:00 2001 From: wfurt Date: Mon, 23 Jul 2018 22:17:08 -0700 Subject: [PATCH 1/3] add back simplified proxy configuration --- .../SocketsHttpHandler/HttpSystemProxy.cs | 5 +++++ .../tests/UnitTests/HttpSystemProxyTest.cs | 22 ++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpSystemProxy.cs b/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpSystemProxy.cs index 4cf0ab4ea67c..95d1c33a39ad 100644 --- a/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpSystemProxy.cs +++ b/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpSystemProxy.cs @@ -67,6 +67,11 @@ private HttpSystemProxy(WinInetProxyHelper proxyHelper, SafeWinHttpHandle sessio if (proxyHelper.ManualSettingsOnly) { ParseProxyConfig(proxyHelper.Proxy, out _insecureProxyUri, out _secureProxyUri); + if (_insecureProxyUri == null && _secureProxyUri == null) + { + // If advanced parsing by protocol fails, fall-back to simplified string. + _insecureProxyUri = _secureProxyUri = GetUriFromString(proxyHelper.Proxy); + } if (!string.IsNullOrWhiteSpace(proxyHelper.ProxyBypass)) { diff --git a/src/System.Net.Http/tests/UnitTests/HttpSystemProxyTest.cs b/src/System.Net.Http/tests/UnitTests/HttpSystemProxyTest.cs index 756eae36c1e7..9b3b4cdf1f47 100644 --- a/src/System.Net.Http/tests/UnitTests/HttpSystemProxyTest.cs +++ b/src/System.Net.Http/tests/UnitTests/HttpSystemProxyTest.cs @@ -64,6 +64,27 @@ public void HttpProxy_SystemProxy_Loaded(string rawProxyString, bool hasInsecure }, rawProxyString, hasInsecureProxy.ToString(), hasSecureProxy.ToString()).Dispose(); } + [Theory] + [InlineData("localhost:1234")] + [InlineData("123.123.123.123")] + public void HttpProxy_SystemProxy_Loaded(string rawProxyString) + { + RemoteInvoke((proxyString) => + { + IWebProxy p; + + FakeRegistry.Reset(); + + FakeRegistry.WinInetProxySettings.Proxy = proxyString; + WinInetProxyHelper proxyHelper = new WinInetProxyHelper(); + + Assert.True(HttpSystemProxy.TryCreate(out p)); + Assert.NotNull(p); + + return SuccessExitCode; + }, rawProxyString).Dispose(); + } + [Theory] [InlineData("http://localhost/", true)] [InlineData("http://127.0.0.1/", true)] @@ -144,7 +165,6 @@ public void HttpProxy_Local_Parsing(string bypass, int count) [InlineData("http://;")] [InlineData("http=;")] [InlineData(" ; ")] - [InlineData("proxy.contoso.com")] public void HttpProxy_InvalidSystemProxy_Null(string rawProxyString) { RemoteInvoke((proxyString) => From 8ce969d855a51f33d2af13ef395ebe663a9ad8a1 Mon Sep 17 00:00:00 2001 From: wfurt Date: Mon, 23 Jul 2018 23:01:52 -0700 Subject: [PATCH 2/3] add tracing --- .../src/System/Net/Http/SocketsHttpHandler/HttpSystemProxy.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpSystemProxy.cs b/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpSystemProxy.cs index 95d1c33a39ad..ba53573a1d5a 100644 --- a/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpSystemProxy.cs +++ b/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpSystemProxy.cs @@ -66,10 +66,11 @@ private HttpSystemProxy(WinInetProxyHelper proxyHelper, SafeWinHttpHandle sessio 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 string. + // If advance parsing by protocol fails, fall-back to simplified parsing. _insecureProxyUri = _secureProxyUri = GetUriFromString(proxyHelper.Proxy); } From 7e5ab386e16476e5b9f88368061a25c92795435e Mon Sep 17 00:00:00 2001 From: wfurt Date: Tue, 24 Jul 2018 09:07:33 -0700 Subject: [PATCH 3/3] feedback from review --- .../Net/Http/SocketsHttpHandler/HttpSystemProxy.cs | 2 +- .../tests/UnitTests/HttpSystemProxyTest.cs | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpSystemProxy.cs b/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpSystemProxy.cs index ba53573a1d5a..8fab9bc6a77d 100644 --- a/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpSystemProxy.cs +++ b/src/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpSystemProxy.cs @@ -70,7 +70,7 @@ private HttpSystemProxy(WinInetProxyHelper proxyHelper, SafeWinHttpHandle sessio ParseProxyConfig(proxyHelper.Proxy, out _insecureProxyUri, out _secureProxyUri); if (_insecureProxyUri == null && _secureProxyUri == null) { - // If advance parsing by protocol fails, fall-back to simplified parsing. + // If advanced parsing by protocol fails, fall-back to simplified parsing. _insecureProxyUri = _secureProxyUri = GetUriFromString(proxyHelper.Proxy); } diff --git a/src/System.Net.Http/tests/UnitTests/HttpSystemProxyTest.cs b/src/System.Net.Http/tests/UnitTests/HttpSystemProxyTest.cs index 9b3b4cdf1f47..74e995e2dcee 100644 --- a/src/System.Net.Http/tests/UnitTests/HttpSystemProxyTest.cs +++ b/src/System.Net.Http/tests/UnitTests/HttpSystemProxyTest.cs @@ -65,11 +65,11 @@ public void HttpProxy_SystemProxy_Loaded(string rawProxyString, bool hasInsecure } [Theory] - [InlineData("localhost:1234")] - [InlineData("123.123.123.123")] - public void HttpProxy_SystemProxy_Loaded(string rawProxyString) + [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) => + RemoteInvoke((proxyString, expectedString) => { IWebProxy p; @@ -80,9 +80,11 @@ public void HttpProxy_SystemProxy_Loaded(string rawProxyString) 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).Dispose(); + }, rawProxyString, expectedUri).Dispose(); } [Theory]