|
|
@@ -21,32 +21,33 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
|
|
|
_application = application;
|
|
|
}
|
|
|
|
|
|
- public override async Task<bool> ProcessRequestAsync()
|
|
|
+ public override async Task ProcessRequestAsync()
|
|
|
{
|
|
|
- InitializeContext();
|
|
|
-
|
|
|
var context = default(TContext);
|
|
|
var success = true;
|
|
|
|
|
|
try
|
|
|
{
|
|
|
- context = _application.CreateContext(this);
|
|
|
+ InitializeContext();
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ context = _application.CreateContext(this);
|
|
|
+
|
|
|
+ await _application.ProcessRequestAsync(context);
|
|
|
+ }
|
|
|
+ catch (BadHttpRequestException ex)
|
|
|
+ {
|
|
|
+ SetBadRequestState(ex);
|
|
|
+ ReportApplicationError(ex);
|
|
|
+ success = false;
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ ReportApplicationError(ex);
|
|
|
+ success = false;
|
|
|
+ }
|
|
|
|
|
|
- await _application.ProcessRequestAsync(context);
|
|
|
- }
|
|
|
- catch (BadHttpRequestException ex)
|
|
|
- {
|
|
|
- SetBadRequestState(ex);
|
|
|
- ReportApplicationError(ex);
|
|
|
- success = false;
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- ReportApplicationError(ex);
|
|
|
- success = false;
|
|
|
- }
|
|
|
- finally
|
|
|
- {
|
|
|
await CompleteResponseBodyAsync();
|
|
|
_streams.Stop();
|
|
|
|
|
|
@@ -56,36 +57,18 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
|
|
|
// Dispose
|
|
|
}
|
|
|
|
|
|
- if (_onCompleted != null)
|
|
|
+ if (!_requestAborted)
|
|
|
{
|
|
|
- await FireOnCompleted();
|
|
|
+ await ProduceEnd();
|
|
|
+ }
|
|
|
+ else if (!HasResponseStarted && _requestRejectedException == null)
|
|
|
+ {
|
|
|
+ // If the request was aborted and no response was sent, there's no
|
|
|
+ // meaningful status code to log.
|
|
|
+ StatusCode = 0;
|
|
|
+ success = false;
|
|
|
}
|
|
|
- }
|
|
|
-
|
|
|
- if (!_requestAborted)
|
|
|
- {
|
|
|
- await ProduceEnd();
|
|
|
- }
|
|
|
- else if (!HasResponseStarted && _requestRejectedException == null)
|
|
|
- {
|
|
|
- // If the request was aborted and no response was sent, there's no
|
|
|
- // meaningful status code to log.
|
|
|
- StatusCode = 0;
|
|
|
- success = false;
|
|
|
- }
|
|
|
|
|
|
- try
|
|
|
- {
|
|
|
- _application.DisposeContext(context, _applicationException);
|
|
|
- }
|
|
|
- catch (Exception ex)
|
|
|
- {
|
|
|
- // TODO Log this
|
|
|
- _applicationException = _applicationException ?? ex;
|
|
|
- success = false;
|
|
|
- }
|
|
|
- finally
|
|
|
- {
|
|
|
// Complete response writer and request reader pipe sides
|
|
|
_bodyOutput.Dispose();
|
|
|
_bodyInputPipe?.Reader.Complete();
|
|
|
@@ -104,7 +87,36 @@ namespace Microsoft.AspNetCore.Server.IIS.Core
|
|
|
await _readBodyTask;
|
|
|
}
|
|
|
}
|
|
|
- return success;
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ success = false;
|
|
|
+ ReportApplicationError(ex);
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ // We're done with anything that touches the request or response, unblock the client.
|
|
|
+ PostCompletion(ConvertRequestCompletionResults(success));
|
|
|
+
|
|
|
+ if (_onCompleted != null)
|
|
|
+ {
|
|
|
+ await FireOnCompleted();
|
|
|
+ }
|
|
|
+
|
|
|
+ try
|
|
|
+ {
|
|
|
+ _application.DisposeContext(context, _applicationException);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ ReportApplicationError(ex);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static NativeMethods.REQUEST_NOTIFICATION_STATUS ConvertRequestCompletionResults(bool success)
|
|
|
+ {
|
|
|
+ return success ? NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_CONTINUE
|
|
|
+ : NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_FINISH_REQUEST;
|
|
|
}
|
|
|
}
|
|
|
}
|