From efd0bdd9eaf66a361b01739522794ec0c9453d15 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 23 Nov 2006 23:24:47 +0000 Subject: * Added GET-masquarading for HEAD, so request.method will return :get even for HEADs. This will help anyone relying on case request.method to automatically work with HEAD and map.resources will also allow HEADs to all GET actions. Rails automatically throws away the response content in a reply to HEAD, so you dont even need to worry about that. If you, for whatever reason, still need to distinguish between GET and HEAD in some edge case, you can use Request#head? and even Request.headers["REQUEST_METHOD"] for get the "real" answer. Closes #6694 [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5621 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_controller/request.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'actionpack/lib/action_controller') diff --git a/actionpack/lib/action_controller/request.rb b/actionpack/lib/action_controller/request.rb index 505fe0777f..98d28d24b8 100755 --- a/actionpack/lib/action_controller/request.rb +++ b/actionpack/lib/action_controller/request.rb @@ -13,14 +13,18 @@ module ActionController @parameters ||= request_parameters.update(query_parameters).update(path_parameters).with_indifferent_access end - # Returns the HTTP request method as a lowercase symbol (:get, for example) + # Returns the HTTP request method as a lowercase symbol (:get, for example). Note, HEAD is returned as :get + # since the two are supposedly to be functionaly equivilent for all purposes except that HEAD won't return a response + # body (which Rails also takes care of elsewhere). def method @request_method ||= (!parameters[:_method].blank? && @env['REQUEST_METHOD'] == 'POST') ? parameters[:_method].to_s.downcase.to_sym : @env['REQUEST_METHOD'].downcase.to_sym + + @request_method == :head ? :get : @request_method end - # Is this a GET request? Equivalent to request.method == :get + # Is this a GET (or HEAD) request? Equivalent to request.method == :get def get? method == :get end @@ -40,9 +44,10 @@ module ActionController method == :delete end - # Is this a HEAD request? Equivalent to request.method == :head + # Is this a HEAD request? HEAD is mapped as :get for request.method, so here we ask the + # REQUEST_METHOD header directly. Thus, for head, both get? and head? will return true. def head? - method == :head + @env['REQUEST_METHOD'].downcase.to_sym == :head end # Determine whether the body of a HTTP call is URL-encoded (default) -- cgit v1.2.3