From 3088b4f84f802fb84c4750ce25d8fe57c6c0a79e Mon Sep 17 00:00:00 2001 From: Piotr Sarnacki Date: Thu, 5 Aug 2010 23:58:12 +0200 Subject: raise error on invalid HTTP methods or :head passed with :via in routes --- actionpack/lib/action_dispatch/routing/mapper.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'actionpack/lib/action_dispatch/routing/mapper.rb') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index f52fb91e97..d53c10e5f3 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -898,6 +898,15 @@ module ActionDispatch 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) -- cgit v1.2.3