From 62c013d7b18d726d0ce10c3e7a1208d5e0e7fadf Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sun, 25 May 2014 14:11:34 -0700 Subject: pass a request to `matches?` so we can avoid creating excess requests --- actionpack/lib/action_dispatch/routing/mapper.rb | 11 +++++------ actionpack/lib/action_dispatch/routing/route_set.rb | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'actionpack/lib/action_dispatch') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 9656109ed3..702d998447 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -35,19 +35,18 @@ module ActionDispatch def dispatcher?; @dispatcher; end - def matches?(env) - req = @request.new(env) - + def matches?(req) @constraints.all? do |constraint| (constraint.respond_to?(:matches?) && constraint.matches?(req)) || (constraint.respond_to?(:call) && constraint.call(*constraint_args(constraint, req))) end - ensure - req.reset_parameters end def call(env) - matches?(env) ? @app.call(env) : [ 404, {'X-Cascade' => 'pass'}, [] ] + req = @request.new(env) + matches?(req) ? @app.call(env) : [ 404, {'X-Cascade' => 'pass'}, [] ] + ensure + req.reset_parameters end private diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 5839db87f9..7a565635f5 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -704,7 +704,7 @@ module ActionDispatch old_params = req.path_parameters req.path_parameters = old_params.merge params app = route.app - if app.matches?(env) && app.dispatcher? + if app.matches?(req) && app.dispatcher? dispatcher = app.app if dispatcher.controller(params, false) -- cgit v1.2.3