mirror of
https://github.com/github/rails.git
synced 2026-04-04 03:00:58 -04:00
* 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
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
*SVN*
|
||||
|
||||
* 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 don't 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]
|
||||
|
||||
* Update Routing to complain when :controller is not specified by a route. Closes #6669. [Nicholas Seckar]
|
||||
|
||||
* Ensure render_to_string cleans up after itself when an exception is raised. #6658 [rsanheim]
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -274,7 +274,7 @@ class RequestTest < Test::Unit::TestCase
|
||||
end
|
||||
|
||||
def test_symbolized_request_methods
|
||||
[:head, :get, :post, :put, :delete].each do |method|
|
||||
[:get, :post, :put, :delete].each do |method|
|
||||
set_request_method_to method
|
||||
assert_equal method, @request.method
|
||||
end
|
||||
@@ -282,7 +282,7 @@ class RequestTest < Test::Unit::TestCase
|
||||
|
||||
def test_allow_method_hacking_on_post
|
||||
set_request_method_to :post
|
||||
[:head, :get, :put, :delete].each do |method|
|
||||
[:get, :put, :delete].each do |method|
|
||||
@request.instance_eval { @parameters = { :_method => method } ; @request_method = nil }
|
||||
assert_equal method, @request.method
|
||||
end
|
||||
@@ -290,11 +290,18 @@ class RequestTest < Test::Unit::TestCase
|
||||
|
||||
def test_restrict_method_hacking
|
||||
@request.instance_eval { @parameters = { :_method => 'put' } }
|
||||
[:head, :get, :put, :delete].each do |method|
|
||||
[:get, :put, :delete].each do |method|
|
||||
set_request_method_to method
|
||||
assert_equal method, @request.method
|
||||
end
|
||||
end
|
||||
|
||||
def test_head_masquarading_as_get
|
||||
set_request_method_to :head
|
||||
assert_equal :get, @request.method
|
||||
assert @request.get?
|
||||
assert @request.head?
|
||||
end
|
||||
|
||||
protected
|
||||
def set_request_method_to(method)
|
||||
|
||||
Reference in New Issue
Block a user