diff --git a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.RemoteServer.cs b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.RemoteServer.cs index 70d56f44a6e29..732384e64ed24 100644 --- a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.RemoteServer.cs +++ b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.RemoteServer.cs @@ -113,7 +113,6 @@ public async Task SendAsync_MultipleRequestsReusingSameClient_Success(Configurat [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task GetAsync_ResponseContentAfterClientAndHandlerDispose_Success(Configuration.Http.RemoteServer remoteServer) { using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer)) @@ -289,7 +288,6 @@ public static IEnumerable<(Configuration.Http.RemoteServer remoteServer, Uri uri [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task GetAsync_ResponseHeadersRead_ReadFromEachIterativelyDoesntDeadlock(Configuration.Http.RemoteServer remoteServer) { using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer)) @@ -315,7 +313,6 @@ public async Task GetAsync_ResponseHeadersRead_ReadFromEachIterativelyDoesntDead [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task SendAsync_HttpRequestMsgResponseHeadersRead_StatusCodeOK(Configuration.Http.RemoteServer remoteServer) { // Sync API supported only up to HTTP/1.1 @@ -342,14 +339,23 @@ public async Task SendAsync_HttpRequestMsgResponseHeadersRead_StatusCodeOK(Confi [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostAsync_CallMethodTwice_StringContent(Configuration.Http.RemoteServer remoteServer) { using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer)) { string data = "Test String"; var content = new StringContent(data, Encoding.UTF8); - content.Headers.ContentMD5 = TestHelper.ComputeMD5Hash(data); + + if (PlatformDetection.IsBrowser) + { + // [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] + content.Headers.Add("Content-MD5-Skip", "browser"); + } + else + { + content.Headers.ContentMD5 = TestHelper.ComputeMD5Hash(data); + } + HttpResponseMessage response; using (response = await client.PostAsync(remoteServer.VerifyUploadUri, content)) { @@ -358,7 +364,16 @@ public async Task PostAsync_CallMethodTwice_StringContent(Configuration.Http.Rem // Repeat call. content = new StringContent(data, Encoding.UTF8); - content.Headers.ContentMD5 = TestHelper.ComputeMD5Hash(data); + if (PlatformDetection.IsBrowser) + { + // [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] + content.Headers.Add("Content-MD5-Skip", "browser"); + } + else + { + content.Headers.ContentMD5 = TestHelper.ComputeMD5Hash(data); + } + using (response = await client.PostAsync(remoteServer.VerifyUploadUri, content)) { Assert.Equal(HttpStatusCode.OK, response.StatusCode); @@ -368,14 +383,21 @@ public async Task PostAsync_CallMethodTwice_StringContent(Configuration.Http.Rem [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostAsync_CallMethod_UnicodeStringContent(Configuration.Http.RemoteServer remoteServer) { using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer)) { string data = "\ub4f1\uffc7\u4e82\u67ab4\uc6d4\ud1a0\uc694\uc77c\uffda3\u3155\uc218\uffdb"; var content = new StringContent(data, Encoding.UTF8); - content.Headers.ContentMD5 = TestHelper.ComputeMD5Hash(data); + if (PlatformDetection.IsBrowser) + { + // [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] + content.Headers.Add("Content-MD5-Skip", "browser"); + } + else + { + content.Headers.ContentMD5 = TestHelper.ComputeMD5Hash(data); + } using (HttpResponseMessage response = await client.PostAsync(remoteServer.VerifyUploadUri, content)) { @@ -386,12 +408,19 @@ public async Task PostAsync_CallMethod_UnicodeStringContent(Configuration.Http.R [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(VerifyUploadServersStreamsAndExpectedData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostAsync_CallMethod_StreamContent(Configuration.Http.RemoteServer remoteServer, HttpContent content, byte[] expectedData) { using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer)) { - content.Headers.ContentMD5 = TestHelper.ComputeMD5Hash(expectedData); + if (PlatformDetection.IsBrowser) + { + // [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] + content.Headers.Add("Content-MD5-Skip", "browser"); + } + else + { + content.Headers.ContentMD5 = TestHelper.ComputeMD5Hash(expectedData); + } using (HttpResponseMessage response = await client.PostAsync(remoteServer.VerifyUploadUri, content)) { @@ -526,7 +555,6 @@ public static IEnumerable VerifyUploadServersStreamsAndExpectedData [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostAsync_CallMethod_NullContent(Configuration.Http.RemoteServer remoteServer) { using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer)) @@ -548,7 +576,6 @@ public async Task PostAsync_CallMethod_NullContent(Configuration.Http.RemoteServ [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostAsync_CallMethod_EmptyContent(Configuration.Http.RemoteServer remoteServer) { using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer)) @@ -641,7 +668,6 @@ public async Task PostAsync_Redirect_ResultingGetFormattedCorrectly(Configuratio [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostAsync_RedirectWith307_LargePayload(Configuration.Http.RemoteServer remoteServer) { if (remoteServer.HttpVersion == new Version(2, 0)) @@ -657,7 +683,6 @@ public async Task PostAsync_RedirectWith307_LargePayload(Configuration.Http.Remo [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostAsync_RedirectWith302_LargePayload(Configuration.Http.RemoteServer remoteServer) { await PostAsync_Redirect_LargePayload_Helper(remoteServer, 302, false); @@ -686,7 +711,15 @@ private async Task PostAsync_Redirect_LargePayload_Helper(Configuration.Http.Rem 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); + if (PlatformDetection.IsBrowser) + { + // [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] + content.Headers.Add("Content-MD5-Skip", "browser"); + } + else + { + content.Headers.ContentMD5 = TestHelper.ComputeMD5Hash(contentBytes); + } using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer)) using (HttpResponseMessage response = await client.PostAsync(redirectUri, content)) @@ -713,7 +746,6 @@ private async Task PostAsync_Redirect_LargePayload_Helper(Configuration.Http.Rem #if !NETFRAMEWORK [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostAsync_ReuseRequestContent_Success(Configuration.Http.RemoteServer remoteServer) { const string ContentString = "This is the content string."; @@ -759,12 +791,16 @@ public async Task PostAsync_ReuseRequestContent_Success(Configuration.Http.Remot [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(HttpMethodsThatAllowContent))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/53591", TestPlatforms.Browser)] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task SendAsync_SendRequestUsingMethodToEchoServerWithContent_Success( string method, Uri serverUri) { + if (method == "GET" && PlatformDetection.IsBrowser) + { + // [ActiveIssue("https://github.com/dotnet/runtime/issues/53591", TestPlatforms.Browser)] + return; + } + using (HttpClient client = CreateHttpClient()) { var request = new HttpRequestMessage( diff --git a/src/libraries/Common/tests/System/Net/Http/PostScenarioTest.cs b/src/libraries/Common/tests/System/Net/Http/PostScenarioTest.cs index c6654ec7d36dc..d1201244c5aac 100644 --- a/src/libraries/Common/tests/System/Net/Http/PostScenarioTest.cs +++ b/src/libraries/Common/tests/System/Net/Http/PostScenarioTest.cs @@ -30,7 +30,6 @@ public abstract class PostScenarioTest : HttpClientHandlerTestBase #if !NETFRAMEWORK [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostRewindableStreamContentMultipleTimes_StreamContentFullySent(Configuration.Http.RemoteServer remoteServer) { const string requestBody = "ABC"; @@ -56,7 +55,6 @@ public async Task PostRewindableStreamContentMultipleTimes_StreamContentFullySen [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [MemberData(nameof(RemoteServersMemberData))] [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBrowserDomSupportedOrNotBrowser))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostNoContentUsingContentLengthSemantics_Success(Configuration.Http.RemoteServer remoteServer) { await PostHelper(remoteServer, string.Empty, null, @@ -65,7 +63,6 @@ public async Task PostNoContentUsingContentLengthSemantics_Success(Configuration [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostEmptyContentUsingContentLengthSemantics_Success(Configuration.Http.RemoteServer remoteServer) { await PostHelper(remoteServer, string.Empty, new StringContent(string.Empty), @@ -74,7 +71,6 @@ public async Task PostEmptyContentUsingContentLengthSemantics_Success(Configurat [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostEmptyContentUsingChunkedEncoding_Success(Configuration.Http.RemoteServer remoteServer) { await PostHelper(remoteServer, string.Empty, new StringContent(string.Empty), @@ -83,7 +79,6 @@ public async Task PostEmptyContentUsingChunkedEncoding_Success(Configuration.Htt [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostEmptyContentUsingConflictingSemantics_Success(Configuration.Http.RemoteServer remoteServer) { await PostHelper(remoteServer, string.Empty, new StringContent(string.Empty), @@ -92,7 +87,6 @@ public async Task PostEmptyContentUsingConflictingSemantics_Success(Configuratio [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostUsingContentLengthSemantics_Success(Configuration.Http.RemoteServer remoteServer) { await PostHelper(remoteServer, ExpectedContent, new StringContent(ExpectedContent), @@ -101,7 +95,6 @@ public async Task PostUsingContentLengthSemantics_Success(Configuration.Http.Rem [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostUsingChunkedEncoding_Success(Configuration.Http.RemoteServer remoteServer) { await PostHelper(remoteServer, ExpectedContent, new StringContent(ExpectedContent), @@ -110,7 +103,6 @@ public async Task PostUsingChunkedEncoding_Success(Configuration.Http.RemoteServ [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostSyncBlockingContentUsingChunkedEncoding_Success(Configuration.Http.RemoteServer remoteServer) { await PostHelper(remoteServer, ExpectedContent, new SyncBlockingContent(ExpectedContent), @@ -119,7 +111,6 @@ public async Task PostSyncBlockingContentUsingChunkedEncoding_Success(Configurat [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostRepeatedFlushContentUsingChunkedEncoding_Success(Configuration.Http.RemoteServer remoteServer) { await PostHelper(remoteServer, ExpectedContent, new RepeatedFlushContent(ExpectedContent), @@ -128,7 +119,6 @@ public async Task PostRepeatedFlushContentUsingChunkedEncoding_Success(Configura [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostUsingUsingConflictingSemantics_UsesChunkedSemantics(Configuration.Http.RemoteServer remoteServer) { await PostHelper(remoteServer, ExpectedContent, new StringContent(ExpectedContent), @@ -137,7 +127,6 @@ public async Task PostUsingUsingConflictingSemantics_UsesChunkedSemantics(Config [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostUsingNoSpecifiedSemantics_UsesChunkedSemantics(Configuration.Http.RemoteServer remoteServer) { await PostHelper(remoteServer, ExpectedContent, new StringContent(ExpectedContent), @@ -157,7 +146,6 @@ public static IEnumerable RemoteServersAndLargeContentSizes() [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory] [MemberData(nameof(RemoteServersAndLargeContentSizes))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostLargeContentUsingContentLengthSemantics_Success(Configuration.Http.RemoteServer remoteServer, int contentLength) { var rand = new Random(42); @@ -226,7 +214,6 @@ public async Task PostNonRewindableContentUsingAuth_PreAuthenticate_Success(Conf [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [MemberData(nameof(RemoteServersMemberData))] [ConditionalTheory(typeof(PlatformDetection), nameof(PlatformDetection.IsBrowserDomSupportedOrNotBrowser))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task PostAsync_EmptyContent_ContentTypeHeaderNotSent(Configuration.Http.RemoteServer remoteServer) { using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer)) @@ -262,7 +249,15 @@ public async Task PostAsync_EmptyContent_ContentTypeHeaderNotSent(Configuration. // Compute MD5 of request body data. This will be verified by the server when it // receives the request. - requestContent.Headers.ContentMD5 = TestHelper.ComputeMD5Hash(requestBody); + if (PlatformDetection.IsBrowser) + { + // [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] + requestContent.Headers.Add("Content-MD5-Skip", "browser"); + } + else + { + requestContent.Headers.ContentMD5 = TestHelper.ComputeMD5Hash(requestBody); + } } if (useChunkedEncodingUpload) diff --git a/src/libraries/Common/tests/System/Net/Http/ResponseStreamTest.cs b/src/libraries/Common/tests/System/Net/Http/ResponseStreamTest.cs index 40638272b6373..1a6cc656e9257 100644 --- a/src/libraries/Common/tests/System/Net/Http/ResponseStreamTest.cs +++ b/src/libraries/Common/tests/System/Net/Http/ResponseStreamTest.cs @@ -128,7 +128,6 @@ public async Task GetStreamAsync_ReadToEnd_Success(Configuration.Http.RemoteServ [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task GetAsync_UseResponseHeadersReadAndCallLoadIntoBuffer_Success(Configuration.Http.RemoteServer remoteServer) { using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer)) @@ -148,7 +147,6 @@ public async Task GetAsync_UseResponseHeadersReadAndCallLoadIntoBuffer_Success(C [OuterLoop("Uses external servers", typeof(PlatformDetection), nameof(PlatformDetection.LocalEchoServerIsNotAvailable))] [Theory, MemberData(nameof(RemoteServersMemberData))] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task GetAsync_UseResponseHeadersReadAndCopyToMemoryStream_Success(Configuration.Http.RemoteServer remoteServer) { using (HttpClient client = CreateHttpClientForRemoteServer(remoteServer)) diff --git a/src/libraries/Common/tests/System/Net/Http/TestHelper.cs b/src/libraries/Common/tests/System/Net/Http/TestHelper.cs index 352f4e714782a..98c19464db941 100644 --- a/src/libraries/Common/tests/System/Net/Http/TestHelper.cs +++ b/src/libraries/Common/tests/System/Net/Http/TestHelper.cs @@ -41,9 +41,13 @@ public static bool JsonMessageContainsKey(string message, string key) bool chunkedUpload, string requestBody) { - // Verify that response body from the server was corrected received by comparing MD5 hash. - byte[] actualMD5Hash = ComputeMD5Hash(responseContent); - Assert.Equal(expectedMD5Hash, actualMD5Hash); + // [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] + if (!PlatformDetection.IsBrowser) + { + // Verify that response body from the server was corrected received by comparing MD5 hash. + byte[] actualMD5Hash = ComputeMD5Hash(responseContent); + Assert.Equal(expectedMD5Hash, actualMD5Hash); + } // Verify upload semantics: 'Content-Length' vs. 'Transfer-Encoding: chunked'. if (requestBody != null) diff --git a/src/libraries/Common/tests/System/Net/Prerequisites/NetCoreServer/Handlers/VerifyUploadHandler.cs b/src/libraries/Common/tests/System/Net/Prerequisites/NetCoreServer/Handlers/VerifyUploadHandler.cs index 69d3190d35be0..3608f6211a3d6 100644 --- a/src/libraries/Common/tests/System/Net/Prerequisites/NetCoreServer/Handlers/VerifyUploadHandler.cs +++ b/src/libraries/Common/tests/System/Net/Prerequisites/NetCoreServer/Handlers/VerifyUploadHandler.cs @@ -32,40 +32,41 @@ public static async Task InvokeAsync(HttpContext context) // Get request body. byte[] requestBodyBytes = await ReadAllRequestBytesAsync(context); - // Check MD5 checksum for non-empty request body. - if (requestBodyBytes.Length > 0) + // Skip MD5 checksum for empty request body + // or for requests which opt to skip it due to [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] + if (requestBodyBytes.Length == 0 || !string.IsNullOrEmpty(context.Request.Headers["Content-MD5-Skip"])) { - // Get expected MD5 hash of request body. - string expectedHash = context.Request.Headers["Content-MD5"]; - if (string.IsNullOrEmpty(expectedHash)) - { - context.Response.StatusCode = 400; - context.Response.SetStatusDescription("Missing 'Content-MD5' request header"); - return; - } + context.Response.StatusCode = 200; + return; + } - // Compute MD5 hash of received request body. - string actualHash; - using (MD5 md5 = MD5.Create()) - { - byte[] hash = md5.ComputeHash(requestBodyBytes); - actualHash = Convert.ToBase64String(hash); - } + // Get expected MD5 hash of request body. + string expectedHash = context.Request.Headers["Content-MD5"]; + if (string.IsNullOrEmpty(expectedHash)) + { + context.Response.StatusCode = 400; + context.Response.SetStatusDescription("Missing 'Content-MD5' request header"); + return; + } - if (expectedHash == actualHash) - { - context.Response.StatusCode = 200; - } - else - { - context.Response.StatusCode = 400; - context.Response.SetStatusDescription("Received request body fails MD5 checksum"); - } + // Compute MD5 hash of received request body. + string actualHash; + using (MD5 md5 = MD5.Create()) + { + byte[] hash = md5.ComputeHash(requestBodyBytes); + actualHash = Convert.ToBase64String(hash); } - else + + if (expectedHash == actualHash) { context.Response.StatusCode = 200; } + else + { + context.Response.StatusCode = 400; + context.Response.SetStatusDescription("Received request body fails MD5 checksum"); + } + } private static async Task ReadAllRequestBytesAsync(HttpContext context) diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs index 60300e8afff70..73a543ac12a21 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs @@ -347,7 +347,6 @@ public async Task SendAsync_RequestHeaderInResponse_Success(string name, string [Theory] [InlineData(false)] [InlineData(true)] - [ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)] public async Task SendAsync_GetWithValidHostHeader_Success(bool withPort) { if (UseVersion == HttpVersion.Version30) @@ -362,7 +361,9 @@ public async Task SendAsync_GetWithValidHostHeader_Success(bool withPort) } var m = new HttpRequestMessage(HttpMethod.Get, Configuration.Http.SecureRemoteEchoServer) { Version = UseVersion }; - m.Headers.Host = withPort ? Configuration.Http.SecureHost + ":" + Configuration.Http.SecurePort : Configuration.Http.SecureHost; + m.Headers.Host = !PlatformDetection.LocalEchoServerIsAvailable && withPort + ? Configuration.Http.SecureHost + ":" + Configuration.Http.SecurePort + : Configuration.Http.SecureHost; using (HttpClient client = CreateHttpClient()) using (HttpResponseMessage response = await client.SendAsync(TestAsync, m))