Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ public HttpConnectionPool(HttpConnectionPoolManager poolManager, HttpConnectionK
Debug.Assert(port != 0);
Debug.Assert(sslHostName == null);
Debug.Assert(proxyUri != null);
Debug.Assert(proxyUri.IdnHost == host && proxyUri.Port == port);
break;

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,18 @@ private static Uri GetUriFromString(string value)
else
{
host = value.Substring(0, separatorIndex);
if (!UInt16.TryParse(value.AsSpan(separatorIndex + 1), out port))
int endIndex = separatorIndex + 1;
// Strip any trailing characters after port number.
while (endIndex < value.Length)
{
if (!char.IsDigit(value[endIndex]))
{
break;
}
endIndex += 1;
}

if (!ushort.TryParse(value.AsSpan(separatorIndex + 1, endIndex - separatorIndex - 1), out port))
{
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down
18 changes: 16 additions & 2 deletions src/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2180,6 +2180,18 @@ public async Task Dispose_DisposingHandlerCancelsActiveOperationsWithoutResponse
return;
}

if (PlatformDetection.IsFullFramework)
{
// Skip test on .NET Framework. It will sometimes not throw TaskCanceledException.
// Instead it might throw the following top-level and inner exceptions depending
// on race conditions.
//
// System.Net.Http.HttpRequestException : Error while copying content to a stream.
// ---- System.IO.IOException : The read operation failed, see inner exception.
//-------- System.Net.WebException : The request was aborted: The request was canceled.
return;
}

await LoopbackServer.CreateServerAsync(async (server1, url1) =>
{
await LoopbackServer.CreateServerAsync(async (server2, url2) =>
Expand Down Expand Up @@ -2658,8 +2670,10 @@ public async Task PostAsync_Redirect_LargePayload_Helper(int statusCode, bool ex
}
}

[OuterLoop] // TODO: Issue #11345
[Theory, MemberData(nameof(EchoServers))] // NOTE: will not work for in-box System.Net.Http.dll due to disposal of request content
[OuterLoop("Uses external server")]
[Theory, MemberData(nameof(EchoServers))]
[SkipOnTargetFramework(TargetFrameworkMonikers.NetFramework, ".NET Framework disposes request content after send")]
[ActiveIssue(31104, TestPlatforms.AnyUnix)]
public async Task PostAsync_ReuseRequestContent_Success(Uri remoteServer)
{
const string ContentString = "This is the content string.";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ public void HttpProxy_EnvironmentProxy_Loaded()
[InlineData("domain\\foo:bar@1.1.1.1", "1.1.1.1", "80", "foo", "bar")]
[InlineData("domain%5Cfoo:bar@1.1.1.1", "1.1.1.1", "80", "foo", "bar")]
[InlineData("HTTP://ABC.COM/", "abc.com", "80", null, null)]
[InlineData("http://10.30.62.64:7890/", "10.30.62.64", "7890", null, null)]
[InlineData("http://1.2.3.4:8888/foo", "1.2.3.4", "8888", null, null)]
public void HttpProxy_Uri_Parsing(string _input, string _host, string _port, string _user , string _password)
{
RemoteInvoke((input, host, port, user, password) =>
Expand Down
24 changes: 23 additions & 1 deletion src/System.Net.Http/tests/UnitTests/HttpSystemProxyTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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) =>
Expand Down
13 changes: 12 additions & 1 deletion src/System.Net.Requests/src/System/Net/HttpWebRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1138,11 +1138,22 @@ private async Task<WebResponse> SendRequest()

Debug.Assert(handler.UseProxy); // Default of handler.UseProxy is true.
Debug.Assert(handler.Proxy == null); // Default of handler.Proxy is null.

// HttpClientHandler default is to use a proxy which is the system proxy.
// This is indicated by the properties 'UseProxy == true' and 'Proxy == null'.
//
// However, HttpWebRequest doesn't have a separate 'UseProxy' property. Instead,
// the default of the 'Proxy' property is a non-null IWebProxy object which is the
// system default proxy object. If the 'Proxy' property were actually null, then
// that means don't use any proxy.
//
// So, we need to map the desired HttpWebRequest proxy settings to equivalent
// HttpClientHandler settings.
if (_proxy == null)
{
handler.UseProxy = false;
}
else
else if (!object.ReferenceEquals(_proxy, WebRequest.GetSystemWebProxy()))
{
handler.Proxy = _proxy;
}
Expand Down
2 changes: 1 addition & 1 deletion tools-local/ILAsmVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.3-servicing-26724-06
2.1.3-servicing-26724-06