コード例 #1
0
        /// <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());
        }
コード例 #2
0
ファイル: HttpServer.cs プロジェクト: tdbrian/Platibus
        protected async Task Accept(HttpListenerContext context)
        {
            var resourceRequest = new HttpListenerRequestAdapter(context.Request, context.User);
            var resourceResponse = new HttpListenerResponseAdapter(context.Response);
            try
            {
                Log.DebugFormat("Routing {0} request for resource {1} from {2}...",
                    context.Request.HttpMethod, context.Request.Url, context.Request.RemoteEndPoint);

                await _resourceRouter.Route(resourceRequest, resourceResponse);

                Log.DebugFormat("{0} request for resource {1} handled successfully",
                    context.Request.HttpMethod, context.Request.Url);
            }
            catch (Exception ex)
            {
                var exceptionHandler = new HttpExceptionHandler(resourceRequest, resourceResponse, Log);
                exceptionHandler.HandleException(ex);
            }
            finally
            {
                context.Response.Close();
            }
        }