From 8bd406c5f76a2b87ad77259cf4d8bc2d082e3536 Mon Sep 17 00:00:00 2001 From: David Shulman Date: Sat, 13 Apr 2019 20:16:43 -0700 Subject: [PATCH] Improve HttpClient POST with REDIRECT tests (dotnet/corefx#36848) This PR is similar to dotnet/corefx#36801 and dotnet/corefx#36828 which improved upload tests stability. Modify the POST with REDIRECT test to use the VerifyUpload endpoint which avoids having to echo back the large request body. Closes dotnet/corefx#36220 Commit migrated from https://github.com/dotnet/corefx/commit/52d4723aaa8e561a6f36589a6d1e112287c0308b --- .../tests/FunctionalTests/HttpClientHandlerTest.cs | 23 ++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.cs index 4e51c73..9ab045a 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.cs @@ -2246,7 +2246,13 @@ namespace System.Net.Http.Functional.Tests public async Task PostAsync_Redirect_LargePayload_Helper(int statusCode, bool expectRedirectToPost) { - using (var fs = new FileStream(Path.Combine(Path.GetTempPath(), Path.GetTempFileName()), FileMode.Create, FileAccess.ReadWrite, FileShare.None, 0x1000, FileOptions.DeleteOnClose)) + using (var fs = new FileStream( + Path.Combine(Path.GetTempPath(), Path.GetTempFileName()), + FileMode.Create, + FileAccess.ReadWrite, + FileShare.None, + 0x1000, + FileOptions.DeleteOnClose)) { string contentString = string.Join("", Enumerable.Repeat("Content", 100000)); byte[] contentBytes = Encoding.UTF32.GetBytes(contentString); @@ -2254,10 +2260,18 @@ namespace System.Net.Http.Functional.Tests fs.Flush(flushToDisk: true); fs.Position = 0; - Uri redirectUri = Configuration.Http.RedirectUriForDestinationUri(false, statusCode, Configuration.Http.SecureRemoteEchoServer, 1); + Uri redirectUri = Configuration.Http.RedirectUriForDestinationUri( + secure: false, + statusCode: statusCode, + destinationUri: Configuration.Http.SecureRemoteVerifyUploadServer, + hops: 1); + var content = new StreamContent(fs); + + // Compute MD5 of request body data. This will be verified by the server when it receives the request. + content.Headers.ContentMD5 = TestHelper.ComputeMD5Hash(contentBytes); using (HttpClient client = CreateHttpClient()) - using (HttpResponseMessage response = await client.PostAsync(redirectUri, new StreamContent(fs))) + using (HttpResponseMessage response = await client.PostAsync(redirectUri, content)) { try { @@ -2271,7 +2285,8 @@ namespace System.Net.Http.Functional.Tests if (expectRedirectToPost) { - Assert.InRange(response.Content.Headers.ContentLength.GetValueOrDefault(), contentBytes.Length, int.MaxValue); + IEnumerable headerValue = response.Headers.GetValues("X-HttpRequest-Method"); + Assert.Equal("POST", headerValue.First()); } } } -- 2.7.4