@@ -1738,11 +1738,17 @@ public async Task FrameAfterTrailers_UnexpectedFrameError()
17381738 {
17391739 new KeyValuePair < string , string > ( "TestName" , "TestValue" ) ,
17401740 } ;
1741- var requestStream = await InitializeConnectionAndStreamsAsync ( _noopApplication ) ;
1741+ var tcs = new TaskCompletionSource ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
1742+ var requestStream = await InitializeConnectionAndStreamsAsync ( async c =>
1743+ {
1744+ // Send headers
1745+ await c . Response . Body . FlushAsync ( ) ;
1746+
1747+ await tcs . Task ;
1748+ } ) ;
17421749
17431750 await requestStream . SendHeadersAsync ( headers , endStream : false ) ;
17441751
1745- // The app no-ops quickly. Wait for it here so it's not a race with the error response.
17461752 await requestStream . ExpectHeadersAsync ( ) ;
17471753
17481754 await requestStream . SendDataAsync ( Encoding . UTF8 . GetBytes ( "Hello world" ) ) ;
@@ -1752,6 +1758,8 @@ public async Task FrameAfterTrailers_UnexpectedFrameError()
17521758 await requestStream . WaitForStreamErrorAsync (
17531759 Http3ErrorCode . UnexpectedFrame ,
17541760 expectedErrorMessage : CoreStrings . FormatHttp3StreamErrorFrameReceivedAfterTrailers ( Http3Formatting . ToFormattedType ( Http3FrameType . Data ) ) ) ;
1761+
1762+ tcs . SetResult ( ) ;
17551763 }
17561764
17571765 [ Fact ]
@@ -2434,24 +2442,68 @@ await outboundcontrolStream.SendSettingsAsync(new List<Http3PeerSetting>
24342442
24352443 Assert . Equal ( Internal . Http3 . Http3SettingType . MaxFieldSectionSize , maxFieldSetting . Key ) ;
24362444 Assert . Equal ( 100 , maxFieldSetting . Value ) ;
2437-
2445+ }
2446+
2447+ [ Fact ]
2448+ public async Task PostRequest_ServerReadsPartialAndFinishes_SendsBodyWithEndStream ( )
2449+ {
2450+ var startingTcs = new TaskCompletionSource < int > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
2451+ var appTcs = new TaskCompletionSource < int > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
2452+ var clientTcs = new TaskCompletionSource < int > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
24382453 var headers = new [ ]
24392454 {
2440- new KeyValuePair < string , string > ( HeaderNames . Method , "GET" ) ,
24412455 new KeyValuePair < string , string > ( HeaderNames . Path , "/" ) ,
24422456 new KeyValuePair < string , string > ( HeaderNames . Scheme , "http" ) ,
24432457 } ;
2458+ var requestStream = await InitializeConnectionAndStreamsAsync ( async context =>
2459+ {
2460+ var buffer = new byte [ 1024 ] ;
2461+ try
2462+ {
2463+ // Read 100 bytes
2464+ var readCount = 0 ;
2465+ while ( readCount < 100 )
2466+ {
2467+ readCount += await context . Request . Body . ReadAsync ( buffer . AsMemory ( readCount , 100 - readCount ) ) ;
2468+ }
24442469
2470+ await context . Response . Body . WriteAsync ( buffer . AsMemory ( 0 , 100 ) ) ;
24452471 var requestStream = await CreateRequestStream ( ) . DefaultTimeout ( ) ;
2472+ await clientTcs . Task . DefaultTimeout ( ) ;
2473+ appTcs . SetResult ( 0 ) ;
2474+ }
2475+ catch ( Exception ex )
2476+ {
2477+ appTcs . SetException ( ex ) ;
2478+ }
2479+ } ) ;
24462480 await requestStream . SendHeadersAsync ( new [ ]
2481+ var sourceData = new byte [ 1024 ] ;
2482+ for ( var i = 0 ; i < sourceData . Length ; i++ )
24472483 {
2484+ sourceData [ i ] = ( byte ) ( i % byte . MaxValue ) ;
2485+ }
24482486 new KeyValuePair < string , string > ( HeaderNames . Path, "/ ") ,
2449- new KeyValuePair < string , string > ( HeaderNames . Scheme , "http" ) ,
2487+ await requestStream . SendDataAsync ( sourceData ) ;
24502488 new KeyValuePair < string , string > ( HeaderNames . Method, "GET ") ,
2451- new KeyValuePair < string , string > ( HeaderNames . Authority , "localhost:80" ) ,
2489+ var decodedHeaders = await requestStream . ExpectHeadersAsync ( ) ;
2490+ Assert . Equal ( 2 , decodedHeaders . Count ) ;
2491+ Assert . Equal ( "200 ", decodedHeaders[HeaderNames.Status]);
24522492 } , endStream : true ) ;
2493+ var data = await requestStream . ExpectDataAsync ( ) ;
2494+
2495+ Assert . Equal ( sourceData . AsMemory ( 0 , 100 ) . ToArray ( ) , data . ToArray ( ) ) ;
2496+
2497+ clientTcs . SetResult ( 0 ) ;
2498+ await appTcs . Task ;
2499+
2500+ await requestStream . ExpectReceiveEndOfStream ( ) ;
24532501
2454- await requestStream . WaitForStreamErrorAsync ( Http3ErrorCode . InternalError , "The encoded HTTP headers length exceeds the limit specified by the peer of 100 bytes." ) ;
2502+ // TODO(JamesNK): Await the server aborting the sending half of the request stream.
2503+ // https://github.com/dotnet/aspnetcore/issues/33575
2504+ await Task . Delay ( 1000 ) ;
2505+
2506+ // Logged without an exception.
24552507 }
24562508 }
24572509}
0 commit comments