Exemple #1
0
        protected override Task OnConsumeAsync()
        {
            try
            {
                if (TryRead(out var readResult))
                {
                    AdvanceTo(readResult.Buffer.End);

                    if (readResult.IsCompleted)
                    {
                        return(Task.CompletedTask);
                    }
                }
            }
            catch (BadHttpRequestException ex)
            {
                // At this point, the response has already been written, so this won't result in a 4XX response;
                // however, we still need to stop the request processing loop and log.
                _context.SetBadRequestState(ex);
                return(Task.CompletedTask);
            }
            catch (InvalidOperationException ex)
            {
                var connectionAbortedException = new ConnectionAbortedException(CoreStrings.ConnectionAbortedByApplication, ex);
                _context.ReportApplicationError(connectionAbortedException);

                // Have to abort the connection because we can't finish draining the request
                _context.StopProcessingNextRequest();
                return(Task.CompletedTask);
            }

            return(OnConsumeAsyncAwaited());
        }
 public override void Complete(Exception exception)
 {
     _readerCompleted = true;
     _context.ReportApplicationError(exception);
 }