From 3eaf525213ccef5c63c9e296fa643ad416a3f84c Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Fri, 15 Jan 2010 12:35:18 -0600 Subject: Make HEAD method masquerade as GET so requests are routed correctly --- actionpack/lib/action_dispatch/http/request.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'actionpack/lib/action_dispatch/http/request.rb') diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index 6e8a5dcb8a..3d0aab8a06 100755 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -35,7 +35,8 @@ module ActionDispatch # :get. If the request \method is not listed in the HTTP_METHODS # constant above, an UnknownHttpMethod exception is raised. def request_method - HTTP_METHOD_LOOKUP[super] || raise(ActionController::UnknownHttpMethod, "#{super}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}") + method = env["rack.methodoverride.original_method"] || env["REQUEST_METHOD"] + HTTP_METHOD_LOOKUP[method] || raise(ActionController::UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}") end # Returns the HTTP request \method used for action processing as a @@ -43,7 +44,8 @@ module ActionDispatch # method returns :get for a HEAD request because the two are # functionally equivalent from the application's perspective.) def method - request_method == :head ? :get : request_method + method = env["REQUEST_METHOD"] + HTTP_METHOD_LOOKUP[method] || raise(ActionController::UnknownHttpMethod, "#{method}, accepted HTTP methods are #{HTTP_METHODS.to_sentence(:locale => :en)}") end # Is this a GET (or HEAD) request? Equivalent to request.method == :get. @@ -53,17 +55,17 @@ module ActionDispatch # Is this a POST request? Equivalent to request.method == :post. def post? - request_method == :post + method == :post end # Is this a PUT request? Equivalent to request.method == :put. def put? - request_method == :put + method == :put end # Is this a DELETE request? Equivalent to request.method == :delete. def delete? - request_method == :delete + method == :delete end # Is this a HEAD request? Since request.method sees HEAD as :get, -- cgit v1.2.3