From d3eb92d95a694905a80668dcde1fb49e2d08f388 Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Thu, 3 Jul 2014 21:32:14 -0700 Subject: Avoid duplicating routes for HEAD requests. Follow up to rails#15321 Instead of duplicating the routes, we will first match the HEAD request to HEAD routes. If no match is found, we will then map the HEAD request to GET routes. --- actionpack/test/journey/router_test.rb | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) (limited to 'actionpack/test/journey') diff --git a/actionpack/test/journey/router_test.rb b/actionpack/test/journey/router_test.rb index 2e7e8e1bea..8fc965adf4 100644 --- a/actionpack/test/journey/router_test.rb +++ b/actionpack/test/journey/router_test.rb @@ -503,6 +503,25 @@ module ActionDispatch assert called end + def test_recognize_head_route + path = Path::Pattern.from_string "/books(/:action(.:format))" + app = Object.new + conditions = { request_method: 'HEAD' } + @router.routes.add_route(app, path, conditions, {}) + + env = rails_env( + 'PATH_INFO' => '/books/list.rss', + 'REQUEST_METHOD' => 'HEAD' + ) + + called = false + @router.recognize(env) do |r, params| + called = true + end + + assert called + end + def test_recognize_head_request_as_get_route path = Path::Pattern.from_string "/books(/:action(.:format))" app = Object.new @@ -561,7 +580,7 @@ module ActionDispatch end def rails_env env, klass = ActionDispatch::Request - klass.new env + klass.new(rack_env(env)) end def rack_env env -- cgit v1.2.3