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)
|
||||
}
|
||||
|
||||
routes =
|
||||
if req.head?
|
||||
match_head_routes(routes, req)
|
||||
else
|
||||
match_routes(routes, req)
|
||||
end
|
||||
if req.head?
|
||||
routes = match_head_routes(routes, req)
|
||||
else
|
||||
routes.select! { |r| r.matches?(req) }
|
||||
end
|
||||
|
||||
routes.sort_by!(&:precedence)
|
||||
|
||||
|
@ -131,24 +130,17 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
def match_head_routes(routes, req)
|
||||
verb_specific_routes = routes.select(&:requires_matching_verb?)
|
||||
head_routes = match_routes(verb_specific_routes, req)
|
||||
head_routes = routes.select { |r| r.requires_matching_verb? && r.matches?(req) }
|
||||
return head_routes unless head_routes.empty?
|
||||
|
||||
if head_routes.empty?
|
||||
begin
|
||||
req.request_method = "GET"
|
||||
match_routes(routes, req)
|
||||
ensure
|
||||
req.request_method = "HEAD"
|
||||
end
|
||||
else
|
||||
head_routes
|
||||
begin
|
||||
req.request_method = "GET"
|
||||
routes.select! { |r| r.matches?(req) }
|
||||
routes
|
||||
ensure
|
||||
req.request_method = "HEAD"
|
||||
end
|
||||
end
|
||||
|
||||
def match_routes(routes, req)
|
||||
routes.select { |r| r.matches?(req) }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue