IISIntegration 736 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. commit a42c8a33b8b9c8525ad71de004f6e877759bcaf8
  2. Author: Justin Kotalik <[email protected]>
  3. Date: Wed Nov 1 15:48:04 2017 -0700
  4. Return FINISH_REQUEST on request failure (#469)
  5. diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContext.cs b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContext.cs
  6. index 5d3fa722d1e..7dcec90f469 100644
  7. --- a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContext.cs
  8. +++ b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContext.cs
  9. @@ -805,7 +805,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
  10. return _readWebSocketsOperation;
  11. }
  12. - public abstract Task ProcessRequestAsync();
  13. + public abstract Task<bool> ProcessRequestAsync();
  14. public void OnStarting(Func<object, Task> callback, object state)
  15. {
  16. diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContextOfT.cs b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContextOfT.cs
  17. index 9f08ff7a54e..4fbd3b59563 100644
  18. --- a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContextOfT.cs
  19. +++ b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContextOfT.cs
  20. @@ -19,9 +19,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
  21. _application = application;
  22. }
  23. - public override async Task ProcessRequestAsync()
  24. + public override async Task<bool> ProcessRequestAsync()
  25. {
  26. var context = default(TContext);
  27. + var success = true;
  28. try
  29. {
  30. @@ -37,6 +38,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
  31. catch (Exception ex)
  32. {
  33. ReportApplicationError(ex);
  34. + success = false;
  35. }
  36. finally
  37. {
  38. @@ -61,6 +63,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
  39. // If the request was aborted and no response was sent, there's no
  40. // meaningful status code to log.
  41. StatusCode = 0;
  42. + success = false;
  43. }
  44. try
  45. @@ -71,6 +74,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
  46. {
  47. // TODO Log this
  48. _applicationException = _applicationException ?? ex;
  49. + success = false;
  50. }
  51. finally
  52. {
  53. @@ -90,6 +94,7 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
  54. await _readingTask;
  55. }
  56. }
  57. + return success;
  58. }
  59. }
  60. }
  61. diff --git a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpServer.cs b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpServer.cs
  62. index e65afdfb0a3..92602936136 100644
  63. --- a/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpServer.cs
  64. +++ b/src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpServer.cs
  65. @@ -74,10 +74,10 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
  66. if (task.IsCompleted)
  67. {
  68. context.Dispose();
  69. - return NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_CONTINUE;
  70. + return ConvertRequestCompletionResults(task.Result);
  71. }
  72. - task.ContinueWith((t, state) => CompleteRequest((IISHttpContext)state), context);
  73. + task.ContinueWith((t, state) => CompleteRequest((IISHttpContext)state, t), context);
  74. return NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_PENDING;
  75. }
  76. @@ -96,15 +96,21 @@ namespace Microsoft.AspNetCore.Server.IISIntegration
  77. return NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_PENDING;
  78. }
  79. - private static void CompleteRequest(IISHttpContext context)
  80. + private static void CompleteRequest(IISHttpContext context, Task<bool> completedTask)
  81. {
  82. // Post completion after completing the request to resume the state machine
  83. - context.PostCompletion(NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_CONTINUE);
  84. + context.PostCompletion(ConvertRequestCompletionResults(completedTask.Result));
  85. // Dispose the context
  86. context.Dispose();
  87. }
  88. + private static NativeMethods.REQUEST_NOTIFICATION_STATUS ConvertRequestCompletionResults(bool success)
  89. + {
  90. + return success ? NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_CONTINUE
  91. + : NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_FINISH_REQUEST;
  92. + }
  93. +
  94. private class IISContextFactory<T> : IISContextFactory
  95. {
  96. private readonly IHttpApplication<T> _application;