diff --git a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.cs b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.cs index 8b791fb5f55042..7d75901e24aad0 100644 --- a/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.cs +++ b/src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.cs @@ -340,6 +340,7 @@ await LoopbackServerFactory.CreateServerAsync(async (server, url) => [InlineData("nocolon")] [InlineData("no colon")] [InlineData("Content-Length ")] + [ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)] public async Task GetAsync_InvalidHeaderNameValue_ThrowsHttpRequestException(string invalidHeader) { if (UseVersion == HttpVersion30) @@ -353,7 +354,7 @@ await LoopbackServer.CreateClientAndServerAsync(async uri => { await Assert.ThrowsAsync(() => client.GetStringAsync(uri)); } - }, server => server.AcceptConnectionSendCustomResponseAndCloseAsync($"HTTP/1.1 200 OK\r\n{invalidHeader}\r\nContent-Length: 11\r\n\r\nhello world")); + }, server => server.AcceptConnectionSendCustomResponseAndCloseAsync($"HTTP/1.1 200 OK\r\n{invalidHeader}\r\n{LoopbackServer.CorsHeaders}Content-Length: 11\r\n\r\nhello world")); } [Theory] @@ -361,6 +362,7 @@ await LoopbackServer.CreateClientAndServerAsync(async uri => [InlineData(true, false)] [InlineData(false, true)] [InlineData(true, true)] + [ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)] public async Task GetAsync_IncompleteData_ThrowsHttpRequestException(bool failDuringHeaders, bool getString) { if (IsWinHttpHandler) @@ -384,11 +386,12 @@ await LoopbackServer.CreateClientAndServerAsync(async uri => } }, server => failDuringHeaders ? - server.AcceptConnectionSendCustomResponseAndCloseAsync("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n") : - server.AcceptConnectionSendCustomResponseAndCloseAsync("HTTP/1.1 200 OK\r\nContent-Length: 5\r\n\r\nhe")); + server.AcceptConnectionSendCustomResponseAndCloseAsync($"HTTP/1.1 200 OK\r\n{LoopbackServer.CorsHeaders}Content-Length: 5\r\n") : + server.AcceptConnectionSendCustomResponseAndCloseAsync($"HTTP/1.1 200 OK\r\n{LoopbackServer.CorsHeaders}Content-Length: 5\r\n\r\nhe")); } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/42852", TestPlatforms.Browser)] public async Task PostAsync_ManyDifferentRequestHeaders_SentCorrectly() { if (IsWinHttpHandler && UseVersion >= HttpVersion20.Value) @@ -577,7 +580,10 @@ await LoopbackServer.CreateClientAndServerAsync(async uri => { Assert.Equal("1.1", resp.Version.ToString()); Assert.Equal(HttpStatusCode.OK, resp.StatusCode); - Assert.Contains("*", resp.Headers.GetValues("Access-Control-Allow-Origin")); + if(PlatformDetection.IsNotBrowser) + { + Assert.Contains("*", resp.Headers.GetValues("Access-Control-Allow-Origin")); + } Assert.Contains("text/example;charset=utf-8", resp.Headers.GetValues("Accept-Patch")); Assert.Contains("bytes", resp.Headers.AcceptRanges); Assert.Equal(TimeSpan.FromSeconds(12), resp.Headers.Age.GetValueOrDefault()); @@ -593,7 +599,10 @@ await LoopbackServer.CreateClientAndServerAsync(async uri => Assert.Contains("gzip", resp.Content.Headers.ContentEncoding); Assert.Contains("da", resp.Content.Headers.ContentLanguage); Assert.Equal(new Uri("/index.htm", UriKind.Relative), resp.Content.Headers.ContentLocation); - Assert.Equal(Convert.FromBase64String("Q2hlY2sgSW50ZWdyaXR5IQ=="), resp.Content.Headers.ContentMD5); + if(PlatformDetection.IsNotBrowser) + { + Assert.Equal(Convert.FromBase64String("Q2hlY2sgSW50ZWdyaXR5IQ=="), resp.Content.Headers.ContentMD5); + } Assert.Equal("bytes", resp.Content.Headers.ContentRange.Unit); Assert.Equal(21010, resp.Content.Headers.ContentRange.From.GetValueOrDefault()); Assert.Equal(47021, resp.Content.Headers.ContentRange.To.GetValueOrDefault()); @@ -612,7 +621,11 @@ await LoopbackServer.CreateClientAndServerAsync(async uri => Assert.Contains("max-age=2592000; pin-sha256=\"E9CZ9INDbd+2eRQozYqqbQ2yXLVKB9+xcprMF+44U1g=\"", resp.Headers.GetValues("Public-Key-Pins")); Assert.Equal(TimeSpan.FromSeconds(120), resp.Headers.RetryAfter.Delta.GetValueOrDefault()); Assert.Contains(new ProductInfoHeaderValue("Apache", "2.4.1"), resp.Headers.Server); - Assert.Contains("UserID=JohnDoe; Max-Age=3600; Version=1", resp.Headers.GetValues("Set-Cookie")); + + if(PlatformDetection.IsNotBrowser) + { + Assert.Contains("UserID=JohnDoe; Max-Age=3600; Version=1", resp.Headers.GetValues("Set-Cookie")); + } Assert.Contains("max-age=16070400; includeSubDomains", resp.Headers.GetValues("Strict-Transport-Security")); Assert.Contains("Max-Forwards", resp.Headers.Trailer); Assert.Contains("?", resp.Headers.GetValues("Tk")); @@ -639,6 +652,7 @@ await LoopbackServer.CreateClientAndServerAsync(async uri => }, server => server.AcceptConnectionSendCustomResponseAndCloseAsync( $"HTTP/1.1 200 OK{newline}" + $"Access-Control-Allow-Origin:{fold} *{newline}" + + $"Access-Control-Expose-Headers:{fold} *{newline}" + $"Accept-Patch:{fold} text/example;charset=utf-8{newline}" + $"Accept-Ranges:{fold} bytes{newline}" + $"Age: {fold}12{newline}" + @@ -693,6 +707,7 @@ await LoopbackServer.CreateClientAndServerAsync(async uri => dribble ? new LoopbackServer.Options { StreamWrapper = s => new DribbleStream(s) } : null); } + [ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)] [Fact] public async Task GetAsync_NonTraditionalChunkSizes_Accepted() { @@ -712,6 +727,7 @@ await TestHelper.WhenAllCompletedOrAnyFailed( server.AcceptConnectionSendCustomResponseAndCloseAsync( "HTTP/1.1 200 OK\r\n" + "Connection: close\r\n" + + LoopbackServer.CorsHeaders + "Transfer-Encoding: chunked\r\n" + "\r\n" + "4 \r\n" + // whitespace after size @@ -757,6 +773,7 @@ await LoopbackServer.CreateServerAsync(async (server, url) => using (HttpClient client = CreateHttpClient()) { string partialResponse = "HTTP/1.1 200 OK\r\n" + + LoopbackServer.CorsHeaders + "Transfer-Encoding: chunked\r\n" + "\r\n" + $"{chunkSize}\r\n"; @@ -792,6 +809,7 @@ await LoopbackServer.CreateClientAndServerAsync(async url => }, server => server.AcceptConnectionSendCustomResponseAndCloseAsync( "HTTP/1.1 200 OK\r\n" + "Connection: close\r\n" + + LoopbackServer.CorsHeaders + "Transfer-Encoding: chunked\r\n" + "\r\n" + "5\r\n" + @@ -820,7 +838,7 @@ await LoopbackServer.CreateServerAsync(async (server, url) => var tcs = new TaskCompletionSource(); Task serverTask = server.AcceptConnectionAsync(async connection => { - await connection.ReadRequestHeaderAndSendCustomResponseAsync("HTTP/1.1 200 OK\r\nTransfer-Encoding: chunked\r\n\r\n"); + await connection.ReadRequestHeaderAndSendCustomResponseAsync("HTTP/1.1 200 OK\r\n" + LoopbackServer.CorsHeaders + "Transfer-Encoding: chunked\r\n\r\n"); try { while (!cts.IsCancellationRequested) // infinite to make sure implementation doesn't OOM @@ -840,6 +858,7 @@ await LoopbackServer.CreateServerAsync(async (server, url) => } [Fact] + [SkipOnPlatform(TestPlatforms.Browser, "CORS is required on Browser")] public async Task SendAsync_TransferEncodingSetButNoRequestContent_Throws() { var req = new HttpRequestMessage(HttpMethod.Post, "http://bing.com") { Version = UseVersion }; @@ -871,6 +890,7 @@ await server.AcceptConnectionAsync(async connection => await connection.ReadRequestHeaderAndSendCustomResponseAsync( "HTTP/1.1 200 OK\r\n" + $"Date: {DateTimeOffset.UtcNow:R}\r\n" + + LoopbackServer.CorsHeaders + "Content-Length: 16000\r\n" + "\r\n" + "less than 16000 bytes"); @@ -894,6 +914,7 @@ await connection.ReadRequestHeaderAndSendCustomResponseAsync( [InlineData(true)] [InlineData(false)] [InlineData(null)] + [ActiveIssue("https://github.com/dotnet/runtime/issues/54159", TestPlatforms.Browser)] public async Task ReadAsStreamAsync_HandlerProducesWellBehavedResponseStream(bool? chunked) { if (IsWinHttpHandler && UseVersion >= HttpVersion20.Value) @@ -1059,6 +1080,7 @@ await server.AcceptConnectionAsync(async connection => } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/54159", TestPlatforms.Browser)] public async Task ReadAsStreamAsync_EmptyResponseBody_HandlerProducesWellBehavedResponseStream() { if (IsWinHttpHandler && UseVersion >= HttpVersion20.Value) @@ -1223,6 +1245,7 @@ await LoopbackServerFactory.CreateServerAsync(async (server3, url3) => [Theory] [InlineData(99)] [InlineData(1000)] + [ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)] public async Task GetAsync_StatusCodeOutOfRange_ExpectedException(int statusCode) { if (UseVersion == HttpVersion30) @@ -1239,6 +1262,7 @@ await LoopbackServer.CreateServerAsync(async (server, url) => await server.AcceptConnectionSendCustomResponseAndCloseAsync( $"HTTP/1.1 {statusCode}\r\n" + $"Date: {DateTimeOffset.UtcNow:R}\r\n" + + LoopbackServer.CorsHeaders + "Connection: close\r\n" + "\r\n"); @@ -1267,6 +1291,7 @@ public async Task GetAsync_UnicodeHostName_SuccessStatusCodeInResponse() #region Post Methods Tests [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/53876", TestPlatforms.Browser)] public async Task GetAsync_ExpectContinueTrue_NoContent_StillSendsHeader() { if (IsWinHttpHandler && UseVersion >= HttpVersion20.Value) @@ -1493,6 +1518,7 @@ await server.AcceptConnectionAsync(async connection => } [Fact] + [ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)] public async Task SendAsync_Expect100Continue_RequestBodyFails_ThrowsContentException() { if (IsWinHttpHandler) @@ -1589,6 +1615,7 @@ await server.AcceptConnectionAsync(async connection => } [Fact] + [SkipOnPlatform(TestPlatforms.Browser, "Switching protocol is not supported on Browser")] public async Task SendAsync_101SwitchingProtocolsResponse_Success() { // WinHttpHandler and CurlHandler will hang, waiting for additional response. @@ -1629,6 +1656,7 @@ await connection.ReadRequestHeaderAndSendCustomResponseAsync( [Theory] [InlineData(false)] [InlineData(true)] + [ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)] public async Task PostAsync_ThrowFromContentCopy_RequestFails(bool syncFailure) { if (UseVersion == HttpVersion30) @@ -1664,6 +1692,7 @@ await LoopbackServer.CreateServerAsync(async (server, uri) => [Theory] [InlineData(HttpStatusCode.MethodNotAllowed, "Custom description")] [InlineData(HttpStatusCode.MethodNotAllowed, "")] + [ActiveIssue("https://github.com/dotnet/runtime/issues/54163", TestPlatforms.Browser)] public async Task GetAsync_CallMethod_ExpectedStatusLine(HttpStatusCode statusCode, string reasonPhrase) { if (LoopbackServerFactory.Version >= HttpVersion20.Value) @@ -1681,13 +1710,14 @@ await LoopbackServer.CreateClientAndServerAsync(async uri => Assert.Equal(reasonPhrase, response.ReasonPhrase); } }, server => server.AcceptConnectionSendCustomResponseAndCloseAsync( - $"HTTP/1.1 {(int)statusCode} {reasonPhrase}\r\nContent-Length: 0\r\n\r\n")); + $"HTTP/1.1 {(int)statusCode} {reasonPhrase}\r\n{LoopbackServer.CorsHeaders}Content-Length: 0\r\n\r\n")); } #endregion #region Version tests + [SkipOnPlatform(TestPlatforms.Browser, "Version is not supported on Browser")] [Fact] public async Task SendAsync_RequestVersion10_ServerReceivesVersion10Request() { @@ -1701,6 +1731,7 @@ public async Task SendAsync_RequestVersion10_ServerReceivesVersion10Request() Assert.Equal(new Version(1, 0), receivedRequestVersion); } + [SkipOnPlatform(TestPlatforms.Browser, "Version is not supported on Browser")] [Fact] public async Task SendAsync_RequestVersion11_ServerReceivesVersion11Request() { @@ -1708,6 +1739,7 @@ public async Task SendAsync_RequestVersion11_ServerReceivesVersion11Request() Assert.Equal(new Version(1, 1), receivedRequestVersion); } + [SkipOnPlatform(TestPlatforms.Browser, "Version is not supported on Browser")] [Fact] public async Task SendAsync_RequestVersionNotSpecified_ServerReceivesVersion11Request() { diff --git a/src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs b/src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs index 438ca23626f750..d0935a9977df74 100644 --- a/src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs +++ b/src/libraries/Common/tests/System/Net/Http/LoopbackServer.cs @@ -210,7 +210,7 @@ public async Task> AcceptConnectionSendResponseAndCloseAsync(HttpSt // We'll close the connection after reading the request header and sending the response. await AcceptConnectionAsync(async connection => { - lines = await connection.ReadRequestHeaderAndSendResponseAsync(statusCode, additionalHeaders + LoopbackServer.CorsHeaders + "Connection: close\r\n", content).ConfigureAwait(false); + lines = await connection.ReadRequestHeaderAndSendResponseAsync(statusCode, additionalHeaders + "Connection: close\r\n", content).ConfigureAwait(false); }).ConfigureAwait(false); return lines; diff --git a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpRequestMessageTest.cs b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpRequestMessageTest.cs index 167d5a0504c962..7be058bedb02a1 100644 --- a/src/libraries/System.Net.Http/tests/FunctionalTests/HttpRequestMessageTest.cs +++ b/src/libraries/System.Net.Http/tests/FunctionalTests/HttpRequestMessageTest.cs @@ -12,7 +12,6 @@ namespace System.Net.Http.Functional.Tests { - [ConditionalClass(typeof(PlatformDetection), nameof(PlatformDetection.IsNotBrowser))] public class HttpRequestMessageTest : HttpClientHandlerTestBase { private readonly Version _expectedRequestMessageVersion = HttpVersion.Version11; @@ -229,6 +228,10 @@ public void ToString_DefaultAndNonDefaultInstance_DumpAllFields() [InlineData("HEAD")] public async Task HttpRequest_BodylessMethod_NoContentLength(string method) { + if(PlatformDetection.IsBrowser && (method=="DELETE" || method=="OPTIONS")){ + // [ActiveIssue("https://github.com/dotnet/runtime/issues/42852", TestPlatforms.Browser)] //TODO pre-flight OPTIONS + return; + } using (HttpClient client = CreateHttpClient()) { await LoopbackServer.CreateServerAsync(async (server, uri) =>