diff --git a/src/kemal/ext/context.cr b/src/kemal/ext/context.cr index 6b99095..06f95ad 100644 --- a/src/kemal/ext/context.cr +++ b/src/kemal/ext/context.cr @@ -32,6 +32,10 @@ class HTTP::Server @response.status_code = status_code end + def route + route_lookup.payload.as(Route) + end + def route_lookup Kemal::RouteHandler::INSTANCE.lookup_route(@request.override_method.as(String), @request.path) end diff --git a/src/kemal/route_handler.cr b/src/kemal/route_handler.cr index e9eb575..ae75cb5 100644 --- a/src/kemal/route_handler.cr +++ b/src/kemal/route_handler.cr @@ -42,8 +42,7 @@ module Kemal # Processes the route if it's a match. Otherwise renders 404. private def process_request(context) raise Kemal::Exceptions::RouteNotFound.new(context) unless context.route_defined? - route = context.route_lookup.payload.as(Route) - content = route.handler.call(context) + content = context.route.handler.call(context) ensure if Kemal.config.error_handlers.has_key?(context.response.status_code) raise Kemal::Exceptions::CustomException.new(context)