Skip to content

Commit 70298e8

Browse files
authored
add back parsing for simple configuration (dotnet/corefx#31314)
* add back simplified proxy configuration * add tracing * feedback from review Commit migrated from dotnet/corefx@2c5f290
1 parent 3ba4870 commit 70298e8

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

src/libraries/System.Net.Http/src/System/Net/Http/SocketsHttpHandler/HttpSystemProxy.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,13 @@ private HttpSystemProxy(WinInetProxyHelper proxyHelper, SafeWinHttpHandle sessio
6666

6767
if (proxyHelper.ManualSettingsOnly)
6868
{
69+
if (NetEventSource.IsEnabled) NetEventSource.Info(proxyHelper, $"ManualSettingsUsed, {proxyHelper.Proxy}");
6970
ParseProxyConfig(proxyHelper.Proxy, out _insecureProxyUri, out _secureProxyUri);
71+
if (_insecureProxyUri == null && _secureProxyUri == null)
72+
{
73+
// If advanced parsing by protocol fails, fall-back to simplified parsing.
74+
_insecureProxyUri = _secureProxyUri = GetUriFromString(proxyHelper.Proxy);
75+
}
7076

7177
if (!string.IsNullOrWhiteSpace(proxyHelper.ProxyBypass))
7278
{

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

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,29 @@ public void HttpProxy_SystemProxy_Loaded(string rawProxyString, bool hasInsecure
6464
}, rawProxyString, hasInsecureProxy.ToString(), hasSecureProxy.ToString()).Dispose();
6565
}
6666

67+
[Theory]
68+
[InlineData("localhost:1234", "http://localhost:1234/")]
69+
[InlineData("123.123.123.123", "http://123.123.123.123/")]
70+
public void HttpProxy_SystemProxy_Loaded(string rawProxyString, string expectedUri)
71+
{
72+
RemoteInvoke((proxyString, expectedString) =>
73+
{
74+
IWebProxy p;
75+
76+
FakeRegistry.Reset();
77+
78+
FakeRegistry.WinInetProxySettings.Proxy = proxyString;
79+
WinInetProxyHelper proxyHelper = new WinInetProxyHelper();
80+
81+
Assert.True(HttpSystemProxy.TryCreate(out p));
82+
Assert.NotNull(p);
83+
Assert.Equal(expectedString, p.GetProxy(new Uri(fooHttp)).ToString());
84+
Assert.Equal(expectedString, p.GetProxy(new Uri(fooHttps)).ToString());
85+
86+
return SuccessExitCode;
87+
}, rawProxyString, expectedUri).Dispose();
88+
}
89+
6790
[Theory]
6891
[InlineData("http://localhost/", true)]
6992
[InlineData("http://127.0.0.1/", true)]
@@ -144,7 +167,6 @@ public void HttpProxy_Local_Parsing(string bypass, int count)
144167
[InlineData("http://;")]
145168
[InlineData("http=;")]
146169
[InlineData(" ; ")]
147-
[InlineData("proxy.contoso.com")]
148170
public void HttpProxy_InvalidSystemProxy_Null(string rawProxyString)
149171
{
150172
RemoteInvoke((proxyString) =>

0 commit comments

Comments
 (0)