@@ -399,6 +399,46 @@ await connection.Receive(
399
399
Assert . False ( loggedHigherThanDebug ) ;
400
400
}
401
401
402
+ [ Fact ]
403
+ public async Task IncompleteRequestBodyDoesNotLogAsApplicationError ( )
404
+ {
405
+ var logMessageReceived = new TaskCompletionSource ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
406
+
407
+ // Listen for the expected log message
408
+ TestSink . MessageLogged += context =>
409
+ {
410
+ if ( context . LoggerName == "Microsoft.AspNetCore.Server.Kestrel"
411
+ && context . EventId . Id == 13
412
+ && context . LogLevel > LogLevel . Debug )
413
+ {
414
+ logMessageReceived . SetResult ( ) ;
415
+ }
416
+ } ;
417
+
418
+ await using var server = new TestServer ( async context =>
419
+ {
420
+ var buffer = new byte [ 1024 ] ;
421
+
422
+ // Attempt to read more of the body than will show up.
423
+ await context . Request . Body . ReadAsync ( buffer , 0 , buffer . Length ) ;
424
+ } , new TestServiceContext ( LoggerFactory ) ) ;
425
+
426
+ using ( var connection = server . CreateConnection ( ) )
427
+ {
428
+ await connection . Send (
429
+ "POST / HTTP/1.1" ,
430
+ "Host:" ,
431
+ "Connection: keep-alive" ,
432
+ "Content-Type: application/json" ,
433
+ "Content-Length: 100" , // Declare a larger body than will be sent
434
+ "" ,
435
+ "" ) ;
436
+ }
437
+
438
+ // Log message should not have appeared.
439
+ await Assert . ThrowsAsync < TimeoutException > ( ( ) => logMessageReceived . Task . TimeoutAfter ( TimeSpan . FromSeconds ( 1 ) ) ) ;
440
+ }
441
+
402
442
[ Fact ]
403
443
public async Task ConnectionResetBetweenRequestsIsLoggedAsDebug ( )
404
444
{
0 commit comments