Beispiel #1
0
        private async Task <HandlerType> WrapHandler(HttpContext aspNetContext, HandlerWrapper handlerWrapper)
        {
            var context  = new Context(aspNetContext, Plugins);
            var request  = context.Request;
            var response = context.Response;

            var status = HandlerType.Continue;

            try
            {
                foreach (var middleware in _middlewareStack)
                {
                    status = await middleware.Invoke(request, response);

                    if (status != HandlerType.Continue)
                    {
                        return(status);
                    }
                }
                if (status == HandlerType.Continue)
                {
                    status = await handlerWrapper.Invoke(request, response);
                }
                return(status);
            }
            catch (Exception e)
            {
                return(await HandleException(context, status, e));
            }
        }
Beispiel #2
0
        private async Task WrapHandler(HttpContext context, HandlerWrapper handlerWrapper)
        {
            var req = new Request(context, Plugins);
            var res = new Response(context, Plugins);

            try
            {
                foreach (var middleware in _middlewareStack)
                {
                    if (res.Closed)
                    {
                        return;
                    }
                    await middleware.Process(req, res);
                }
                await handlerWrapper.Invoke(req, res);
            }
            catch (Exception e)
            {
                if (!res.Closed)
                {
                    if (RespondWithExceptionDetails)
                    {
                        await res.SendString(e.ToString(), status : HttpStatusCode.InternalServerError);
                    }
                    else
                    {
                        await res.SendStatus(HttpStatusCode.InternalServerError);
                    }
                }
            }
        }