/// <summary>
        /// Accepts an incoming HTTP request
        /// </summary>
        /// <param name="context">The HTTP listener context</param>
        /// <returns>Returns a task that will complete when the request has been handled</returns>
        protected async Task Accept(HttpListenerContext context)
        {
            var request          = context.Request;
            var remote           = request.RemoteEndPoint?.ToString();
            var resourceRequest  = new HttpListenerRequestAdapter(context.Request, context.User);
            var resourceResponse = new HttpListenerResponseAdapter(context.Response);

            try
            {
                await _resourceRouter.Route(resourceRequest, resourceResponse);
            }
            catch (Exception ex)
            {
                var exceptionHandler = new HttpExceptionHandler(resourceRequest, resourceResponse, _diagnosticService);
                exceptionHandler.HandleException(ex);
            }
            finally
            {
                context.Response.Close();
            }

            await _diagnosticService.EmitAsync(
                new HttpEventBuilder(this, HttpEventType.HttpResponseSent)
            {
                Remote = remote,
                Uri    = request.Url,
                Method = request.HttpMethod
            }.Build());
        }
Beispiel #2
0
        private async Task ProcessRequestAsync(HttpContextBase context)
        {
            var diagnosticService = _configuration.DiagnosticService;

            await diagnosticService.EmitAsync(
                new HttpEventBuilder(this, HttpEventType.HttpRequestReceived)
            {
                Remote = context.Request.UserHostAddress,
                Uri    = context.Request.Url,
                Method = context.Request.HttpMethod
            }.Build());

            var resourceRequest  = new HttpRequestAdapter(context.Request, context.User);
            var resourceResponse = new HttpResponseAdapter(context.Response);

            try
            {
                await _resourceRouter.Route(resourceRequest, resourceResponse);
            }
            catch (Exception ex)
            {
                var exceptionHandler = new HttpExceptionHandler(resourceRequest, resourceResponse, diagnosticService);
                exceptionHandler.HandleException(ex);
            }

            await diagnosticService.EmitAsync(
                new HttpEventBuilder(this, HttpEventType.HttpRequestReceived)
            {
                Remote = context.Request.UserHostAddress,
                Uri    = context.Request.Url,
                Method = context.Request.HttpMethod,
                Status = context.Response.StatusCode
            }.Build());
        }
Beispiel #3
0
        private async Task HandlePlatibusRequest(HttpContext context)
        {
            await _diagnosticService.EmitAsync(
                new HttpEventBuilder(this, HttpEventType.HttpRequestReceived)
            {
                Remote = context.Connection.RemoteIpAddress?.ToString(),
                Uri    = context.Request.GetUri(),
                Method = context.Request.Method
            }.Build());

            var resourceRequest  = new HttpRequestAdapter(context.Request);
            var resourceResponse = new HttpResponseAdapter(context.Response);

            try
            {
                await _resourceRouter.Route(resourceRequest, resourceResponse);
            }
            catch (Exception ex)
            {
                var exceptionHandler = new HttpExceptionHandler(resourceRequest, resourceResponse, _diagnosticService);
                exceptionHandler.HandleException(ex);
            }

            await _diagnosticService.EmitAsync(
                new HttpEventBuilder(this, HttpEventType.HttpResponseSent)
            {
                Remote = context.Connection.RemoteIpAddress?.ToString(),
                Uri    = context.Request.GetUri(),
                Method = context.Request.Method,
                Status = context.Response.StatusCode
            }.Build());
        }