aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_controller
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2006-11-23 23:24:47 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2006-11-23 23:24:47 +0000
commitefd0bdd9eaf66a361b01739522794ec0c9453d15 (patch)
tree10244d7ddfbb6718d751066c4bf8ea6cb1565e75 /actionpack/lib/action_controller
parentf15d52fc4ab921f010325adfd543c0a0c29913d2 (diff)
downloadrails-efd0bdd9eaf66a361b01739522794ec0c9453d15.tar.gz
rails-efd0bdd9eaf66a361b01739522794ec0c9453d15.tar.bz2
rails-efd0bdd9eaf66a361b01739522794ec0c9453d15.zip
* 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
Diffstat (limited to 'actionpack/lib/action_controller')
-rwxr-xr-xactionpack/lib/action_controller/request.rb13
1 files changed, 9 insertions, 4 deletions
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)