@@ -21,32 +21,33 @@ public IISHttpContextOfT(MemoryPool<byte> memoryPool, IHttpApplication<TContext>
21
21
_application = application ;
22
22
}
23
23
24
- public override async Task < bool > ProcessRequestAsync ( )
24
+ public override async Task ProcessRequestAsync ( )
25
25
{
26
- InitializeContext ( ) ;
27
-
28
26
var context = default ( TContext ) ;
29
27
var success = true ;
30
28
31
29
try
32
30
{
33
- context = _application . CreateContext ( this ) ;
31
+ InitializeContext ( ) ;
32
+
33
+ try
34
+ {
35
+ context = _application . CreateContext ( this ) ;
36
+
37
+ await _application . ProcessRequestAsync ( context ) ;
38
+ }
39
+ catch ( BadHttpRequestException ex )
40
+ {
41
+ SetBadRequestState ( ex ) ;
42
+ ReportApplicationError ( ex ) ;
43
+ success = false ;
44
+ }
45
+ catch ( Exception ex )
46
+ {
47
+ ReportApplicationError ( ex ) ;
48
+ success = false ;
49
+ }
34
50
35
- await _application . ProcessRequestAsync ( context ) ;
36
- }
37
- catch ( BadHttpRequestException ex )
38
- {
39
- SetBadRequestState ( ex ) ;
40
- ReportApplicationError ( ex ) ;
41
- success = false ;
42
- }
43
- catch ( Exception ex )
44
- {
45
- ReportApplicationError ( ex ) ;
46
- success = false ;
47
- }
48
- finally
49
- {
50
51
await CompleteResponseBodyAsync ( ) ;
51
52
_streams . Stop ( ) ;
52
53
@@ -56,36 +57,18 @@ public override async Task<bool> ProcessRequestAsync()
56
57
// Dispose
57
58
}
58
59
59
- if ( _onCompleted != null )
60
+ if ( ! _requestAborted )
60
61
{
61
- await FireOnCompleted ( ) ;
62
+ await ProduceEnd ( ) ;
63
+ }
64
+ else if ( ! HasResponseStarted && _requestRejectedException == null )
65
+ {
66
+ // If the request was aborted and no response was sent, there's no
67
+ // meaningful status code to log.
68
+ StatusCode = 0 ;
69
+ success = false ;
62
70
}
63
- }
64
-
65
- if ( ! _requestAborted )
66
- {
67
- await ProduceEnd ( ) ;
68
- }
69
- else if ( ! HasResponseStarted && _requestRejectedException == null )
70
- {
71
- // If the request was aborted and no response was sent, there's no
72
- // meaningful status code to log.
73
- StatusCode = 0 ;
74
- success = false ;
75
- }
76
71
77
- try
78
- {
79
- _application . DisposeContext ( context , _applicationException ) ;
80
- }
81
- catch ( Exception ex )
82
- {
83
- // TODO Log this
84
- _applicationException = _applicationException ?? ex ;
85
- success = false ;
86
- }
87
- finally
88
- {
89
72
// Complete response writer and request reader pipe sides
90
73
_bodyOutput . Dispose ( ) ;
91
74
_bodyInputPipe ? . Reader . Complete ( ) ;
@@ -104,7 +87,36 @@ public override async Task<bool> ProcessRequestAsync()
104
87
await _readBodyTask ;
105
88
}
106
89
}
107
- return success ;
90
+ catch ( Exception ex )
91
+ {
92
+ success = false ;
93
+ ReportApplicationError ( ex ) ;
94
+ }
95
+ finally
96
+ {
97
+ // We're done with anything that touches the request or response, unblock the client.
98
+ PostCompletion ( ConvertRequestCompletionResults ( success ) ) ;
99
+
100
+ if ( _onCompleted != null )
101
+ {
102
+ await FireOnCompleted ( ) ;
103
+ }
104
+
105
+ try
106
+ {
107
+ _application . DisposeContext ( context , _applicationException ) ;
108
+ }
109
+ catch ( Exception ex )
110
+ {
111
+ ReportApplicationError ( ex ) ;
112
+ }
113
+ }
114
+ }
115
+
116
+ private static NativeMethods . REQUEST_NOTIFICATION_STATUS ConvertRequestCompletionResults ( bool success )
117
+ {
118
+ return success ? NativeMethods . REQUEST_NOTIFICATION_STATUS . RQ_NOTIFICATION_CONTINUE
119
+ : NativeMethods . REQUEST_NOTIFICATION_STATUS . RQ_NOTIFICATION_FINISH_REQUEST ;
108
120
}
109
121
}
110
122
}
0 commit comments