mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Respect routing precedence for HEAD requests
Fixes the issue described in #18764 - prevents Rack middleware from swallowing up HEAD requests that should have been matched by a higher-precedence `get` route, but still allows Rack middleware to respond to HEAD requests.
This commit is contained in:
parent
5154089c18
commit
34a52c6bce
2 changed files with 4 additions and 4 deletions
|
@ -121,7 +121,8 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
def match_head_routes(routes, req)
|
||||
head_routes = match_routes(routes, req)
|
||||
verb_specific_routes = routes.reject { |route| route.verb == // }
|
||||
head_routes = match_routes(verb_specific_routes, req)
|
||||
|
||||
if head_routes.empty?
|
||||
begin
|
||||
|
|
|
@ -3492,12 +3492,11 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest
|
|||
mount lambda { |env| [200, {}, [env['REQUEST_METHOD']]] }, at: '/'
|
||||
end
|
||||
|
||||
# TODO: HEAD request should match `get /home` rather than the
|
||||
# HEAD request should match `get /home` rather than the
|
||||
# lower-precedence Rack app mounted at `/`.
|
||||
head '/home'
|
||||
assert_response :ok
|
||||
#assert_equal 'test#index', @response.body
|
||||
assert_equal 'HEAD', @response.body
|
||||
assert_equal 'test#index', @response.body
|
||||
|
||||
# But the Rack app can still respond to its own HEAD requests.
|
||||
head '/foobar'
|
||||
|
|
Loading…
Reference in a new issue