@@ -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 ]
@@ -2435,13 +2443,6 @@ await outboundcontrolStream.SendSettingsAsync(new List<Http3PeerSetting>
24352443 Assert . Equal ( Internal . Http3 . Http3SettingType . MaxFieldSectionSize , maxFieldSetting . Key ) ;
24362444 Assert . Equal ( 100 , maxFieldSetting . Value ) ;
24372445
2438- var headers = new [ ]
2439- {
2440- new KeyValuePair < string , string > ( HeaderNames . Method , "GET" ) ,
2441- new KeyValuePair < string , string > ( HeaderNames . Path , "/" ) ,
2442- new KeyValuePair < string , string > ( HeaderNames . Scheme , "http" ) ,
2443- } ;
2444-
24452446 var requestStream = await CreateRequestStream ( ) . DefaultTimeout ( ) ;
24462447 await requestStream . SendHeadersAsync ( new [ ]
24472448 {
@@ -2453,5 +2454,69 @@ await requestStream.SendHeadersAsync(new[]
24532454
24542455 await requestStream . WaitForStreamErrorAsync ( Http3ErrorCode . InternalError , "The encoded HTTP headers length exceeds the limit specified by the peer of 100 bytes." ) ;
24552456 }
2457+
2458+ [ Fact ]
2459+ public async Task PostRequest_ServerReadsPartialAndFinishes_SendsBodyWithEndStream ( )
2460+ {
2461+ var startingTcs = new TaskCompletionSource < int > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
2462+ var appTcs = new TaskCompletionSource < int > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
2463+ var clientTcs = new TaskCompletionSource < int > ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
2464+
2465+ var requestStream = await InitializeConnectionAndStreamsAsync ( async context =>
2466+ {
2467+ var buffer = new byte [ 1024 ] ;
2468+ try
2469+ {
2470+ // Read 100 bytes
2471+ var readCount = 0 ;
2472+ while ( readCount < 100 )
2473+ {
2474+ readCount += await context . Request . Body . ReadAsync ( buffer . AsMemory ( readCount , 100 - readCount ) ) ;
2475+ }
2476+
2477+ await context . Response . Body . WriteAsync ( buffer . AsMemory ( 0 , 100 ) ) ;
2478+ await clientTcs . Task . DefaultTimeout ( ) ;
2479+ appTcs . SetResult ( 0 ) ;
2480+ }
2481+ catch ( Exception ex )
2482+ {
2483+ appTcs . SetException ( ex ) ;
2484+ }
2485+ } ) ;
2486+
2487+ var sourceData = new byte [ 1024 ] ;
2488+ for ( var i = 0 ; i < sourceData . Length ; i ++ )
2489+ {
2490+ sourceData [ i ] = ( byte ) ( i % byte . MaxValue ) ;
2491+ }
2492+
2493+ await requestStream . SendHeadersAsync ( new [ ]
2494+ {
2495+ new KeyValuePair < string , string > ( HeaderNames . Method , "POST" ) ,
2496+ new KeyValuePair < string , string > ( HeaderNames . Path , "/" ) ,
2497+ new KeyValuePair < string , string > ( HeaderNames . Scheme , "http" ) ,
2498+ } ) ;
2499+
2500+ await requestStream . SendDataAsync ( sourceData ) ;
2501+ var decodedHeaders = await requestStream . ExpectHeadersAsync ( ) ;
2502+ Assert . Equal ( 2 , decodedHeaders . Count ) ;
2503+ Assert . Equal ( "200" , decodedHeaders [ HeaderNames . Status ] ) ;
2504+
2505+ var data = await requestStream . ExpectDataAsync ( ) ;
2506+
2507+ Assert . Equal ( sourceData . AsMemory ( 0 , 100 ) . ToArray ( ) , data . ToArray ( ) ) ;
2508+
2509+ clientTcs . SetResult ( 0 ) ;
2510+ await appTcs . Task ;
2511+
2512+ await requestStream . ExpectReceiveEndOfStream ( ) ;
2513+
2514+ // TODO(JamesNK): Await the server aborting the sending half of the request stream.
2515+ // https://github.com/dotnet/aspnetcore/issues/33575
2516+ await Task . Delay ( 1000 ) ;
2517+
2518+ // Logged without an exception.
2519+ Assert . Contains ( LogMessages , m => m . Message . Contains ( "the application completed without reading the entire request body." ) ) ;
2520+ }
24562521 }
24572522}
0 commit comments