Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sync HttpClient Send #34948

Merged
merged 80 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
1e11d42
Moved and fixed code from https://github.com/stephentoub/corefx/tree/…
ManickaP Jan 29, 2020
8a96eab
Sync on HttpMessageInvoker instead of SocketHandler
ManickaP Feb 4, 2020
0db4f95
Merge branch 'master'
ManickaP Feb 6, 2020
8b9baeb
Fix after merge
ManickaP Feb 6, 2020
b4cdb9d
Merge remote-tracking branch 'upstream/master' into mapichov/sync_htt…
ManickaP Feb 7, 2020
3eeff26
Sync HttpClient.Send, including timeout and cancellation
ManickaP Feb 7, 2020
4b9b048
Merge branch 'master' into mapichov/sync_http_api
ManickaP Mar 18, 2020
13b7d33
Fixed compilation after merge.
ManickaP Mar 18, 2020
4fcb464
Merge branch 'master' of github.com:dotnet/runtime into mapichov/sync…
ManickaP Mar 20, 2020
836c6a3
HttpClient Send tests.
ManickaP Mar 23, 2020
de52d34
Merge remote-tracking branch 'upstream/master' into mapichov/sync_htt…
ManickaP Apr 1, 2020
c9b5907
Post merge fixes.
ManickaP Apr 1, 2020
8e6abc8
AutoRedirect and Authenticaton sync tests done.
ManickaP Apr 2, 2020
f930e5f
Cancellation sync tests
ManickaP Apr 2, 2020
bacb741
Merge branch 'master' into mapichov/sync_http_api
ManickaP Apr 8, 2020
25ecee6
Sync Cookie tests.
ManickaP Apr 9, 2020
dd6ca30
Sync HttpClientHandlerTest
ManickaP Apr 9, 2020
8ee2baf
Merge branch 'master' into mapichov/sync_http_api
ManickaP Apr 14, 2020
941f921
Merge branch 'master' into mapichov/sync_http_api
ManickaP Apr 15, 2020
ecee08f
net472 compilaris
ManickaP Apr 15, 2020
34809a5
Removed offloading of client/server tasks to another thread in Loopba…
ManickaP Apr 17, 2020
8824ac9
Merge branch 'master' into mapichov/sync_http_api
ManickaP Apr 17, 2020
a2a653e
Removed unused method.
ManickaP Apr 23, 2020
724241a
Cory's comments.
ManickaP Apr 23, 2020
07699aa
Stephen's nits, renames, comments.
ManickaP Apr 24, 2020
d25d2d6
100-continue todo resolved.
ManickaP Apr 28, 2020
c00d8ea
ByteAtATimeContent sync over async for tests.
ManickaP Apr 28, 2020
9a78f71
HttpClient and HttpContent refactored duplicate code.
ManickaP Apr 30, 2020
bc9bdb9
Merge branch 'master' into mapichov/sync_http_api
ManickaP May 6, 2020
0e7a74d
Merge branch 'master' into mapichov/sync_http_api
ManickaP May 13, 2020
c1de37c
Throwing NSE instead of sync-over-async.
ManickaP May 13, 2020
6de79c2
Fixed compiler constant.
ManickaP May 13, 2020
0a32c84
Reworked tests to use inheritance instead of a test parameter.
ManickaP May 14, 2020
b968275
Fixed throwing NSE and missing sync implementations.
ManickaP May 18, 2020
f173650
Fixed Cancellation tests
ManickaP May 20, 2020
e0b8c0d
More tests fixed.
ManickaP May 21, 2020
77b406f
Moar tests.
ManickaP May 21, 2020
9a32c9d
Even moar tests.
ManickaP May 21, 2020
3da68cb
Removed unnecessary changes.
ManickaP May 21, 2020
5fc5ac0
Fixed tests.
ManickaP May 26, 2020
8b8463c
HttpStream sync write clean up.
ManickaP May 26, 2020
11021c6
Merge branch 'master' into mapichov/sync_http_api
ManickaP May 26, 2020
a0f0a5d
Sync AuthenticateAsClient usage
ManickaP May 26, 2020
0dcf44e
Handle cancellation and subsequent exception mapping.
ManickaP May 29, 2020
6f28a2b
Fixed deadlocking tests
ManickaP May 29, 2020
c8d2336
Merge remote-tracking branch 'upstream/master' into mapichov/sync_htt…
ManickaP May 30, 2020
f8a8219
Merge remote-tracking branch 'upstream/master' into mapichov/sync_htt…
ManickaP Jun 1, 2020
c8b46a6
Fixed merge
ManickaP Jun 1, 2020
4e412e9
Fixed compilaris for browser.
ManickaP Jun 1, 2020
86171b0
Single thread execution tests.
ManickaP Jun 2, 2020
a53aee7
Cancellation tests
ManickaP Jun 3, 2020
9501109
Removed unnecessary changes.
ManickaP Jun 4, 2020
41212be
Missing TestAsync.
ManickaP Jun 4, 2020
b6f86f9
Tests.
ManickaP Jun 4, 2020
52c5601
Timeout tests.
ManickaP Jun 4, 2020
0f90f0c
Clean up after #37441 discussion
ManickaP Jun 5, 2020
453aa6b
Response content timeout test.
ManickaP Jun 5, 2020
157431c
Timeout tests too slow to check for exact call stack line.
ManickaP Jun 5, 2020
bbcc5a1
Merge branch 'master' into mapichov/sync_http_api
ManickaP Jun 5, 2020
d9de995
Review comments.
ManickaP Jun 8, 2020
eeb5fa1
Merge branch 'master' into mapichov/sync_http_api
ManickaP Jun 8, 2020
f20d300
Review comments.
ManickaP Jun 8, 2020
0f8bbd8
Resx review comments.
ManickaP Jun 8, 2020
43ed804
Last review comments.
ManickaP Jun 9, 2020
04d567f
Fail proofing tests.
ManickaP Jun 9, 2020
0f58108
Merge branch 'master' into current
ManickaP Jun 10, 2020
53c24a9
Removed some unnecessary newlines.
ManickaP Jun 10, 2020
1bc2f15
Explanation why the test is skipped.
ManickaP Jun 10, 2020
864b158
ConnectHelper.ConnectAsync split even further.
ManickaP Jun 10, 2020
77669b8
Renamed resource.
ManickaP Jun 10, 2020
c624dd8
Removed check for missing SerializeToStream override from HttpContent.
ManickaP Jun 10, 2020
ed6eb2a
DiagnosticHandler and task status.
ManickaP Jun 10, 2020
851c8b6
The last of the comments
ManickaP Jun 10, 2020
2eb6c2d
Fixed test hanging on 3s timeout.
ManickaP Jun 10, 2020
92f4540
Merge branch 'master' into mapichov/sync_http_api
ManickaP Jun 18, 2020
12d1bca
Merge branch 'master' into mapichov/sync_http_api
ManickaP Jun 19, 2020
7e5c47d
Fixed method visibility
ManickaP Jun 23, 2020
96eccce
Fixed hanging tests.
ManickaP Jun 23, 2020
0355117
Merge branch 'master' into mapichov/sync_http_api
ManickaP Jun 23, 2020
7844fbf
Proofing test against slow infra.
ManickaP Jun 23, 2020
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
4 changes: 2 additions & 2 deletions src/libraries/Common/tests/System/IO/DelegateStream.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,14 @@ public DelegateStream(
_positionSetFunc = positionSetFunc ?? (_ => { throw new NotSupportedException(); });
_positionGetFunc = positionGetFunc ?? (() => { throw new NotSupportedException(); });

_readFunc = readFunc;
_readAsyncFunc = readAsyncFunc ?? ((buffer, offset, count, token) => base.ReadAsync(buffer, offset, count, token));
_readFunc = readFunc ?? ((buffer, offset, count) => readAsyncFunc(buffer, offset, count, default).GetAwaiter().GetResult());

_seekFunc = seekFunc ?? ((_, __) => { throw new NotSupportedException(); });
_setLengthFunc = setLengthFunc ?? (_ => { throw new NotSupportedException(); });

_writeFunc = writeFunc;
_writeAsyncFunc = writeAsyncFunc ?? ((buffer, offset, count, token) => base.WriteAsync(buffer, offset, count, token));
_writeFunc = writeFunc ?? ((buffer, offset, count) => writeAsyncFunc(buffer, offset, count, default).GetAwaiter().GetResult());

_disposeFunc = disposeFunc;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// See the LICENSE file in the project root for more information.

using System.IO;
using System.Threading;
using System.Threading.Tasks;

namespace System.Net.Http.Functional.Tests
Expand All @@ -24,6 +25,11 @@ public ByteAtATimeContent(int length, Task waitToSend, TaskCompletionSource<bool
_millisecondDelayBetweenBytes = millisecondDelayBetweenBytes;
}

#if NETCOREAPP
scalablecory marked this conversation as resolved.
Show resolved Hide resolved
protected override void SerializeToStream(Stream stream, TransportContext context, CancellationToken cancellationToken) =>
SerializeToStreamAsync(stream, context).GetAwaiter().GetResult();
#endif

protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
{
await _waitToSend;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,59 @@ private async Task CreateAndValidateRequest(HttpClientHandler handler, Uri url,

public HttpClientHandler_Authentication_Test(ITestOutputHelper output) : base(output) { }

[Theory]
[MemberData(nameof(Authentication_SocketsHttpHandler_TestData))]
public async Task SocketsHttpHandler_Authentication_Succeeds(string authenticateHeader, bool result)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved from SocketsHttpHandler_HttpClientHandler_Authentication_Test so that it can be shared between SocketsHttpHandlerTests, SyncHttpHandlerTests and WinHttpHandlerTests (excluded test data failing for it).

{
await HttpClientHandler_Authentication_Succeeds(authenticateHeader, result);
}

public static IEnumerable<object[]> Authentication_SocketsHttpHandler_TestData()
{
// These test cases successfully authenticate on SocketsHttpHandler but fail on the other handlers.
// These are legal as per the RFC, so authenticating is the expected behavior.
// See https://github.com/dotnet/runtime/issues/25643 for details.
if (!IsWinHttpHandler)
{
// Unauthorized on WinHttpHandler
yield return new object[] {"Basic realm=\"testrealm1\" basic realm=\"testrealm1\"", true};
yield return new object[] {"Basic something digest something", true};
}
yield return new object[] { "Digest realm=\"[email protected]\", qop=\"auth\", algorithm=MD5-sess, nonce=\"5TsQWLVdgBdmrQ0XsxbDODV+57QdFR34I9HAbC/RVvkK\", " +
"opaque=\"HRPCssKJSGjCrkzDg8OhwpzCiGPChXYjwrI2QmXDnsOS\", charset=UTF-8, userhash=true", true };
yield return new object[] { "dIgEsT realm=\"[email protected]\", qop=\"auth\", algorithm=MD5-sess, nonce=\"5TsQWLVdgBdmrQ0XsxbDODV+57QdFR34I9HAbC/RVvkK\", " +
"opaque=\"HRPCssKJSGjCrkzDg8OhwpzCiGPChXYjwrI2QmXDnsOS\", charset=UTF-8, userhash=true", true };

// These cases fail on WinHttpHandler because of a behavior in WinHttp that causes requests to be duplicated
// when the digest header has certain parameters. See https://github.com/dotnet/runtime/issues/25644 for details.
if (!IsWinHttpHandler)
{
// Timeouts on WinHttpHandler
yield return new object[] { "Digest ", false };
yield return new object[] { "Digest realm=\"testrealm\", nonce=\"testnonce\", algorithm=\"myown\"", false };
}

// These cases fail to authenticate on SocketsHttpHandler, but succeed on the other handlers.
// they are all invalid as per the RFC, so failing is the expected behavior. See https://github.com/dotnet/runtime/issues/25645 for details.
if (!IsWinHttpHandler)
{
// Timeouts on WinHttpHandler
yield return new object[] {"Digest realm=withoutquotes, nonce=withoutquotes", false};
}
yield return new object[] { "Digest realm=\"testrealm\" nonce=\"testnonce\"", false };
yield return new object[] { "Digest realm=\"testrealm1\", nonce=\"testnonce1\" Digest realm=\"testrealm2\", nonce=\"testnonce2\"", false };

// These tests check that the algorithm parameter is treated in case insensitive way.
// WinHTTP only supports plain MD5, so other algorithms are included here.
yield return new object[] { $"Digest realm=\"testrealm\", algorithm=md5-Sess, nonce=\"testnonce\", qop=\"auth\"", true };
if (!IsWinHttpHandler)
{
// Unauthorized on WinHttpHandler
yield return new object[] { $"Digest realm=\"testrealm\", algorithm=sha-256, nonce=\"testnonce\"", true };
yield return new object[] { $"Digest realm=\"testrealm\", algorithm=sha-256-SESS, nonce=\"testnonce\", qop=\"auth\"", true };
}
}

[Theory]
[MemberData(nameof(Authentication_TestData))]
public async Task HttpClientHandler_Authentication_Succeeds(string authenticateHeader, bool result)
Expand Down Expand Up @@ -568,7 +621,7 @@ public async Task Credentials_DomainJoinedServerUsesKerberos_UseIpAddressAndHost
_output.WriteLine(request.RequestUri.AbsoluteUri.ToString());
_output.WriteLine($"Host: {request.Headers.Host}");

using (HttpResponseMessage response = await client.SendAsync(request))
using (HttpResponseMessage response = await client.SendAsync(TestAsync, request))
{
Assert.Equal(HttpStatusCode.OK, response.StatusCode);
string body = await response.Content.ReadAsStringAsync();
Expand Down Expand Up @@ -602,12 +655,11 @@ public async Task Credentials_ServerUsesWindowsAuthentication_Success(string ser
[InlineData("Negotiate")]
public async Task Credentials_ServerChallengesWithWindowsAuth_ClientSendsWindowsAuthHeader(string authScheme)
{
#if WINHTTPHANDLER_TEST
if (UseVersion > HttpVersion.Version11)
if (IsWinHttpHandler && UseVersion >= HttpVersion20.Value)
{
throw new SkipTestException($"Test doesn't support {UseVersion} protocol.");
return;
}
#endif

await LoopbackServerFactory.CreateClientAndServerAsync(
async uri =>
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,32 +40,15 @@ public static IEnumerable<object[]> RemoteServersAndRedirectStatusCodes()
}
}

public static readonly object[][] RedirectStatusCodesOldMethodsNewMethods = {
new object[] { 300, "GET", "GET" },
new object[] { 300, "POST", "GET" },
new object[] { 300, "HEAD", "HEAD" },

new object[] { 301, "GET", "GET" },
new object[] { 301, "POST", "GET" },
new object[] { 301, "HEAD", "HEAD" },

new object[] { 302, "GET", "GET" },
new object[] { 302, "POST", "GET" },
new object[] { 302, "HEAD", "HEAD" },

new object[] { 303, "GET", "GET" },
new object[] { 303, "POST", "GET" },
new object[] { 303, "HEAD", "HEAD" },

new object[] { 307, "GET", "GET" },
new object[] { 307, "POST", "POST" },
new object[] { 307, "HEAD", "HEAD" },

new object[] { 308, "GET", "GET" },
new object[] { 308, "POST", "POST" },
new object[] { 308, "HEAD", "HEAD" },
};

public static IEnumerable<object[]> RedirectStatusCodesOldMethodsNewMethods()
{
foreach (int statusCode in new[] { 300, 301, 302, 303, 307, 308 })
{
yield return new object[] { statusCode, "GET", "GET" };
yield return new object[] { statusCode, "POST", statusCode <= 303 ? "GET" : "POST" };
yield return new object[] { statusCode, "HEAD", "HEAD" };
}
}
public HttpClientHandlerTest_AutoRedirect(ITestOutputHelper output) : base(output) { }

[OuterLoop("Uses external server")]
Expand Down Expand Up @@ -112,7 +95,7 @@ await LoopbackServer.CreateServerAsync(async (origServer, origUrl) =>
{
var request = new HttpRequestMessage(new HttpMethod(oldMethod), origUrl) { Version = UseVersion };

Task<HttpResponseMessage> getResponseTask = client.SendAsync(request);
Task<HttpResponseMessage> getResponseTask = client.SendAsync(TestAsync, request);

await LoopbackServer.CreateServerAsync(async (redirServer, redirUrl) =>
{
Expand Down Expand Up @@ -157,7 +140,7 @@ await LoopbackServer.CreateServerAsync(async (origServer, origUrl) =>
request.Content = new StringContent(ExpectedContent);
request.Headers.TransferEncodingChunked = true;

Task<HttpResponseMessage> getResponseTask = client.SendAsync(request);
Task<HttpResponseMessage> getResponseTask = client.SendAsync(TestAsync, request);

await LoopbackServer.CreateServerAsync(async (redirServer, redirUrl) =>
{
Expand Down
Loading