Esempio n. 1
0
        public override void Handle(HttpRequest request)
        {
            if (request.ProtocolVersion.Major <= 3)
            {
                HttpResponse response;
                try
                {
                    var controller    = this.CreateController(request);
                    var actionInvoker = new NewActionInvoker();
                    var actionResult  = actionInvoker.InvokeAction(controller, request.Action);
                    response = actionResult.GetResponse();
                }
                catch (HttpNotFound exception)
                {
                    response = new HttpResponse(
                        request.ProtocolVersion, HttpStatusCode.NotFound, exception.Message);
                }
                catch (Exception exception)
                {
                    response = new HttpResponse(
                        request.ProtocolVersion, HttpStatusCode.InternalServerError, exception.Message);
                }

                this.Response     = response;
                this.IsSuccessful = true;
            }
            else
            {
                this.IsSuccessful = false;
            }
        }
Esempio n. 2
0
    private HttpResponse Process(HttpRq request)
    {
        if (request.Method.ToLower() == "options")
        {
            var routes =
                Assembly.GetEntryAssembly()
                .GetTypes()
                .Where(x => x.Name.EndsWith("Controller") && typeof(Controller).IsAssignableFrom(x))
                .Select(
                    x => new { x.Name, Methods = x.GetMethods().Where(m => m.ReturnType == typeof(IActionResult)) })
                .SelectMany(
                    x =>
                    x.Methods.Select(
                        m =>
                        string.Format("/{0}/{1}/{{parameter}}", x.Name.Replace("Controller", string.Empty), m.Name)))
                .ToList();

            return(new HttpResponse(
                       request.ProtocolVersion,
                       HttpStatusCode.OK,
                       string.Join(Environment.NewLine, routes)));
        }
        else if (new StaticFileHandler().CanHandle(request))
        {
            return(new StaticFileHandler().Handle(request));
        }
        else if (request.ProtocolVersion.Major <= 3)
        {
            HttpResponse response;
            try
            {
                var controller    = CreateController(request);
                var actionInvoker = new NewActionInvoker();
                var actionResult  = actionInvoker.InvokeAction(controller, request.Action);
                response = actionResult.GetResponse();
            }
            catch (HttpNotFound exception)
            {
                response = new HttpResponse(request.ProtocolVersion, HttpStatusCode.NotFound, exception.Message);
            }
            catch (Exception exception)
            {
                response = new HttpResponse(request.ProtocolVersion, HttpStatusCode.InternalServerError, exception.Message);
            }
            return(response);
        }
        else
        {
            return(new HttpResponse(request.ProtocolVersion, HttpStatusCode.NotImplemented, "Request cannot be handled."));
        }
    }
    private HttpResponse Process(HttpRq request)
    {
        if (request.Method.ToLower() == "options")
        {
            var routes =
                Assembly.GetEntryAssembly()
                    .GetTypes()
                    .Where(x => x.Name.EndsWith("Controller") && typeof(Controller).IsAssignableFrom(x))
                    .Select(
                        x => new { x.Name, Methods = x.GetMethods().Where(m => m.ReturnType == typeof(IActionResult)) })
                    .SelectMany(
                        x =>
                        x.Methods.Select(
                            m =>
                            string.Format("/{0}/{1}/{{parameter}}", x.Name.Replace("Controller", string.Empty), m.Name)))
                    .ToList();

            return new HttpResponse(
                request.ProtocolVersion,
                HttpStatusCode.OK,
                string.Join(Environment.NewLine, routes));
        }
        else if (new StaticFileHandler().CanHandle(request))
        {
            return new StaticFileHandler().Handle(request);
        }
        else if (request.ProtocolVersion.Major <= 3)
        {
            HttpResponse response;
            try
            {
                var controller = CreateController(request);
                var actionInvoker = new NewActionInvoker();
                var actionResult = actionInvoker.InvokeAction(controller, request.Action);
                response = actionResult.GetResponse();
            }
            catch (HttpNotFound exception)
            {
                response = new HttpResponse(request.ProtocolVersion, HttpStatusCode.NotFound, exception.Message);
            }
            catch (Exception exception)
            {
                response = new HttpResponse(request.ProtocolVersion, HttpStatusCode.InternalServerError, exception.Message);
            }
            return response;
        }
        else
        {
            return new HttpResponse(request.ProtocolVersion, HttpStatusCode.NotImplemented, "Request cannot be handled.");
        }
    }