@@ -635,6 +635,15 @@ private async Task ProcessRequests<TContext>(IHttpApplication<TContext> applicat
635
635
// Run the application code for this request
636
636
await application . ProcessRequestAsync ( context ) ;
637
637
638
+ // Trigger OnStarting if it hasn't been called yet and the app hasn't
639
+ // already failed. If an OnStarting callback throws we can go through
640
+ // our normal error handling in ProduceEnd.
641
+ // https://github.com/aspnet/KestrelHttpServer/issues/43
642
+ if ( ! HasResponseStarted && _applicationException == null && _onStarting ? . Count > 0 )
643
+ {
644
+ await FireOnStarting ( ) ;
645
+ }
646
+
638
647
if ( ! _connectionAborted && ! VerifyResponseContentLength ( out var lengthException ) )
639
648
{
640
649
ReportApplicationError ( lengthException ) ;
@@ -655,15 +664,6 @@ private async Task ProcessRequests<TContext>(IHttpApplication<TContext> applicat
655
664
656
665
KestrelEventSource . Log . RequestStop ( this ) ;
657
666
658
- // Trigger OnStarting if it hasn't been called yet and the app hasn't
659
- // already failed. If an OnStarting callback throws we can go through
660
- // our normal error handling in ProduceEnd.
661
- // https://github.com/aspnet/KestrelHttpServer/issues/43
662
- if ( ! HasResponseStarted && _applicationException == null && _onStarting ? . Count > 0 )
663
- {
664
- await FireOnStarting ( ) ;
665
- }
666
-
667
667
// At this point all user code that needs use to the request or response streams has completed.
668
668
// Using these streams in the OnCompleted callback is not allowed.
669
669
StopBodies ( ) ;
@@ -942,7 +942,7 @@ public void ProduceContinue()
942
942
}
943
943
}
944
944
945
- public Task InitializeResponseAsync ( int firstWriteByteCount , bool appCompleted = false )
945
+ public Task InitializeResponseAsync ( int firstWriteByteCount )
946
946
{
947
947
var startingTask = FireOnStarting ( ) ;
948
948
// If return is Task.CompletedTask no awaiting is required
@@ -953,7 +953,7 @@ public Task InitializeResponseAsync(int firstWriteByteCount, bool appCompleted =
953
953
954
954
VerifyInitializeState ( firstWriteByteCount ) ;
955
955
956
- ProduceStart ( appCompleted : appCompleted ) ;
956
+ ProduceStart ( appCompleted : false ) ;
957
957
958
958
return Task . CompletedTask ;
959
959
}
@@ -1050,7 +1050,7 @@ protected Task ProduceEnd()
1050
1050
return WriteSuffix ( ) ;
1051
1051
}
1052
1052
1053
- protected Task WriteSuffix ( )
1053
+ private Task WriteSuffix ( )
1054
1054
{
1055
1055
if ( HasResponseCompleted )
1056
1056
{
0 commit comments