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..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 @@ -66,7 +66,13 @@ 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 parsing. + _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..74e995e2dcee 100644 --- a/src/System.Net.Http/tests/UnitTests/HttpSystemProxyTest.cs +++ b/src/System.Net.Http/tests/UnitTests/HttpSystemProxyTest.cs @@ -64,6 +64,29 @@ public void HttpProxy_SystemProxy_Loaded(string rawProxyString, bool hasInsecure }, rawProxyString, hasInsecureProxy.ToString(), hasSecureProxy.ToString()).Dispose(); } + [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)] @@ -144,7 +167,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) =>