mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #38910 from vinistock/reduce_loops_in_head_route_matching
Reduce loops in head route matching
This commit is contained in:
commit
c1ccc6a0d2
1 changed files with 13 additions and 21 deletions
|
@ -110,12 +110,11 @@ module ActionDispatch
|
||||||
r.path.match?(req.path_info)
|
r.path.match?(req.path_info)
|
||||||
}
|
}
|
||||||
|
|
||||||
routes =
|
if req.head?
|
||||||
if req.head?
|
routes = match_head_routes(routes, req)
|
||||||
match_head_routes(routes, req)
|
else
|
||||||
else
|
routes.select! { |r| r.matches?(req) }
|
||||||
match_routes(routes, req)
|
end
|
||||||
end
|
|
||||||
|
|
||||||
routes.sort_by!(&:precedence)
|
routes.sort_by!(&:precedence)
|
||||||
|
|
||||||
|
@ -131,24 +130,17 @@ module ActionDispatch
|
||||||
end
|
end
|
||||||
|
|
||||||
def match_head_routes(routes, req)
|
def match_head_routes(routes, req)
|
||||||
verb_specific_routes = routes.select(&:requires_matching_verb?)
|
head_routes = routes.select { |r| r.requires_matching_verb? && r.matches?(req) }
|
||||||
head_routes = match_routes(verb_specific_routes, req)
|
return head_routes unless head_routes.empty?
|
||||||
|
|
||||||
if head_routes.empty?
|
begin
|
||||||
begin
|
req.request_method = "GET"
|
||||||
req.request_method = "GET"
|
routes.select! { |r| r.matches?(req) }
|
||||||
match_routes(routes, req)
|
routes
|
||||||
ensure
|
ensure
|
||||||
req.request_method = "HEAD"
|
req.request_method = "HEAD"
|
||||||
end
|
|
||||||
else
|
|
||||||
head_routes
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def match_routes(routes, req)
|
|
||||||
routes.select { |r| r.matches?(req) }
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue