コード例 #1
0
        private HttpStreams StartStreams()
        {
            var streams = new HttpStreams(_httpContext.Request.InputStream, this);

            streams.Start();
            streams.Deconstuct(out Stream request, out Stream response);
            RequestBody  = request;
            ResponseBody = response;
            return(streams);
        }
コード例 #2
0
        private async Task ProcessRequestsAsync <TContext>(IHttpApplication <TContext> application)
        {
            try
            {
                HttpStreams streams = StartStreams();

                OnRequestProcessingStarting();

                var httpContext = application.CreateContext(this);

                _context.ServerContext.Logger.Log("Http context created.", LoggingLevel.Debug);

                try
                {
                    // Run the application code for this request
                    await application.ProcessRequestAsync(httpContext);
                }
                catch (Exception e)
                {
                    _context.ServerContext.Logger.Log("Application process request failed.", LoggingLevel.Error, e);
                    ReportApplicationError(e);
                    //Unexpect exception occurs while processing http request.
                }
                finally
                {
                    // // At this point all user code that needs use to the request or response streams has completed.
                    // Using these streams in the OnCompleted callback is not allowed.
                    StopStreams(streams);

                    _context.ServerContext.Logger.Log("Application processing request is completed.", LoggingLevel.Debug);

                    await FireOnCompleted();

                    //await connection to close.
                    await _context.ConnectionContext.CloseAsync();

                    _context.ServerContext.Logger.Log("Http connection closed.", LoggingLevel.Debug);

                    application.DisposeContext(httpContext, _applicationException);

                    _context.ServerContext.Logger.Log("Http context disposed.", LoggingLevel.Debug);
                }
            }
            catch (BadHttpRequestException e)
            {
                _context.ServerContext.Logger.Log("Http bad request!", LoggingLevel.Error, e);
                //bad http request exception.
            }
            catch (ConnectionResetException e)
            {
                _context.ServerContext.Logger.Log("Connection reset!", LoggingLevel.Error, e);
                //connection reset exception.
            }
            catch (Exception ex)
            {
                _context.ServerContext.Logger.Log("Process request failed!", LoggingLevel.Error, ex);
                //other request process exception occurs.
            }
            finally
            {
                this.Reset();
                OnRequestProcessingEnded();
            }
        }
コード例 #3
0
 private void StopStreams(HttpStreams streams)
 {
     streams?.Stop();
 }