提交 3088b4f8 编写于 作者: P Piotr Sarnacki

raise error on invalid HTTP methods or :head passed with :via in routes

上级 8958f332
......@@ -898,6 +898,15 @@ def match(*args)
return self
end
via = Array.wrap(options[:via]).map(&:to_sym)
if via.include?(:head)
raise ArgumentError, "HTTP method HEAD is invalid in route conditions. Rails processes HEAD requests the same as GETs, returning just the response headers"
end
unless (invalid = via - HTTP_METHODS).empty?
raise ArgumentError, "Invalid HTTP method (#{invalid.join(', ')}) specified in :via"
end
on = options.delete(:on)
if VALID_ON_OPTIONS.include?(on)
args.push(options)
......
......@@ -718,7 +718,7 @@ def test_should_not_allow_invalid_http_methods_for_member_routes
set.draw do
resources :messages do
member do
match :something, :via => :invalid
match :something, :via => [:invalid, :get]
end
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册