Permalink
Browse files

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

  • Loading branch information...
1 parent 8958f33 commit 3088b4f84f802fb84c4750ce25d8fe57c6c0a79e @drogus drogus committed Aug 5, 2010
@@ -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

0 comments on commit 3088b4f

Please sign in to comment.