Skip to content

Commit a0a8ce6

Browse files
authored
[browser][http] test and compatibility improvements (#89504)
1 parent 89030ce commit a0a8ce6

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

src/libraries/Common/tests/System/Net/Http/HttpClientHandlerTest.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ await LoopbackServerFactory.CreateServerAsync(async (server, url) =>
351351
[InlineData("nocolon")]
352352
[InlineData("no colon")]
353353
[InlineData("Content-Length ")]
354-
[ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)]
354+
[SkipOnPlatform(TestPlatforms.Browser, "Browser is relaxed about validating HTTP headers")]
355355
public async Task GetAsync_InvalidHeaderNameValue_ThrowsHttpRequestException(string invalidHeader)
356356
{
357357
if (UseVersion == HttpVersion30)
@@ -373,7 +373,7 @@ await LoopbackServer.CreateClientAndServerAsync(async uri =>
373373
[InlineData(true, false)]
374374
[InlineData(false, true)]
375375
[InlineData(true, true)]
376-
[ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)]
376+
[ActiveIssue("https://github.com/dotnet/runtime/issues/86317", typeof(PlatformDetection), nameof(PlatformDetection.IsNodeJS))]
377377
public async Task GetAsync_IncompleteData_ThrowsHttpRequestException(bool failDuringHeaders, bool getString)
378378
{
379379
if (IsWinHttpHandler)
@@ -386,6 +386,11 @@ public async Task GetAsync_IncompleteData_ThrowsHttpRequestException(bool failDu
386386
return;
387387
}
388388

389+
if (PlatformDetection.IsBrowser && failDuringHeaders)
390+
{
391+
return; // chrome browser doesn't validate this
392+
}
393+
389394
await LoopbackServer.CreateClientAndServerAsync(async uri =>
390395
{
391396
using (HttpClient client = CreateHttpClient())
@@ -763,7 +768,7 @@ await LoopbackServer.CreateClientAndServerAsync(async uri =>
763768
}
764769

765770
[Fact]
766-
[ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)]
771+
[SkipOnPlatform(TestPlatforms.Browser, "TypeError: Failed to fetch on a Browser")]
767772
public async Task GetAsync_NonTraditionalChunkSizes_Accepted()
768773
{
769774
if (LoopbackServerFactory.Version >= HttpVersion20.Value)
@@ -816,7 +821,7 @@ await TestHelper.WhenAllCompletedOrAnyFailed(
816821
[InlineData("xyz")] // non-hex
817822
[InlineData("7gibberish")] // valid size then gibberish
818823
[InlineData("7\v\f")] // unacceptable whitespace
819-
[ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)]
824+
[ActiveIssue("https://github.com/dotnet/runtime/issues/86317", typeof(PlatformDetection), nameof(PlatformDetection.IsNodeJS))]
820825
public async Task GetAsync_InvalidChunkSize_ThrowsHttpRequestException(string chunkSize)
821826
{
822827
if (UseVersion != HttpVersion.Version11)
@@ -849,7 +854,7 @@ await LoopbackServer.CreateServerAsync(async (server, url) =>
849854
}
850855

851856
[Fact]
852-
[ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)]
857+
[ActiveIssue("https://github.com/dotnet/runtime/issues/86317", typeof(PlatformDetection), nameof(PlatformDetection.IsNodeJS))]
853858
public async Task GetAsync_InvalidChunkTerminator_ThrowsHttpRequestException()
854859
{
855860
if (UseVersion != HttpVersion.Version11)
@@ -878,7 +883,7 @@ await LoopbackServer.CreateClientAndServerAsync(async url =>
878883
}
879884

880885
[Fact]
881-
[ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)]
886+
[ActiveIssue("https://github.com/dotnet/runtime/issues/86317", typeof(PlatformDetection), nameof(PlatformDetection.IsNodeJS))]
882887
public async Task GetAsync_InfiniteChunkSize_ThrowsHttpRequestException()
883888
{
884889
if (UseVersion != HttpVersion.Version11)
@@ -1468,7 +1473,7 @@ await LoopbackServerFactory.CreateServerAsync(async (server3, url3) =>
14681473
[Theory]
14691474
[InlineData(99)]
14701475
[InlineData(1000)]
1471-
[ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)]
1476+
[SkipOnPlatform(TestPlatforms.Browser, "Browser is relaxed about validating HTTP headers")]
14721477
public async Task GetAsync_StatusCodeOutOfRange_ExpectedException(int statusCode)
14731478
{
14741479
if (UseVersion == HttpVersion30)
@@ -1743,7 +1748,7 @@ await server.AcceptConnectionAsync(async connection =>
17431748
}
17441749

17451750
[Fact]
1746-
[ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)]
1751+
[SkipOnPlatform(TestPlatforms.Browser, "ExpectContinue not supported on Browser")]
17471752
public async Task SendAsync_Expect100Continue_RequestBodyFails_ThrowsContentException()
17481753
{
17491754
if (IsWinHttpHandler)
@@ -1885,7 +1890,6 @@ await connection.ReadRequestHeaderAndSendCustomResponseAsync(
18851890
[Theory]
18861891
[InlineData(false)]
18871892
[InlineData(true)]
1888-
[ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)]
18891893
public async Task PostAsync_ThrowFromContentCopy_RequestFails(bool syncFailure)
18901894
{
18911895
if (UseVersion == HttpVersion30)

src/libraries/Common/tests/System/Net/Http/ResponseStreamTest.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,14 +268,17 @@ public async Task BrowserHttpHandler_Streaming()
268268
[InlineData(TransferType.ContentLength, TransferError.ContentLengthTooLarge)]
269269
[InlineData(TransferType.Chunked, TransferError.MissingChunkTerminator)]
270270
[InlineData(TransferType.Chunked, TransferError.ChunkSizeTooLarge)]
271-
[ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)]
272271
public async Task ReadAsStreamAsync_InvalidServerResponse_ThrowsIOException(
273272
TransferType transferType,
274273
TransferError transferError)
275274
{
276275
await StartTransferTypeAndErrorServer(transferType, transferError, async uri =>
277276
{
278-
if (IsWinHttpHandler)
277+
if (PlatformDetection.IsBrowser) // TypeError: Failed to fetch
278+
{
279+
await Assert.ThrowsAsync<HttpRequestException>(() => ReadAsStreamHelper(uri));
280+
}
281+
else if (IsWinHttpHandler)
279282
{
280283
await Assert.ThrowsAsync<IOException>(() => ReadAsStreamHelper(uri));
281284
}

src/libraries/System.Net.Http/src/System/Net/Http/BrowserHttpHandler/BrowserHttpHandler.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ private static async Task<WasmFetchResponse> CallFetch(HttpRequestMessage reques
235235
JSObject fetchResponse = await BrowserHttpInterop.CancelationHelper(promise, cancellationToken, abortController, null).ConfigureAwait(true);
236236
return new WasmFetchResponse(fetchResponse, abortRegistration.Value);
237237
}
238+
catch (JSException jse)
239+
{
240+
throw new HttpRequestException(jse.Message, jse);
241+
}
238242
catch (Exception)
239243
{
240244
// this would also trigger abort

src/libraries/System.Net.Http/tests/FunctionalTests/HttpClientHandlerTest.Headers.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
138138
[Theory]
139139
[InlineData("\u05D1\u05F1")]
140140
[InlineData("jp\u30A5")]
141-
[ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)]
141+
[SkipOnPlatform(TestPlatforms.Browser, "Browser is relaxed about validating HTTP headers")]
142142
public async Task SendAsync_InvalidCharactersInHeader_Throw(string value)
143143
{
144144
await LoopbackServerFactory.CreateClientAndServerAsync(async uri =>
@@ -412,7 +412,7 @@ public async Task SendAsync_GetWithInvalidHostHeader_ThrowsException()
412412
}
413413

414414
[Fact]
415-
[ActiveIssue("https://github.com/dotnet/runtime/issues/54160", TestPlatforms.Browser)]
415+
[SkipOnPlatform(TestPlatforms.Browser, "Browser is relaxed about validating HTTP headers")]
416416
public async Task SendAsync_WithZeroLengthHeaderName_Throws()
417417
{
418418
await LoopbackServerFactory.CreateClientAndServerAsync(

0 commit comments

Comments
 (0)