Changeset 5621
- Timestamp:
- 11/23/06 23:24:47 (2 years ago)
- Files:
-
- branches/1-2-pre-release/actionpack/CHANGELOG (modified) (1 diff)
- branches/1-2-pre-release/actionpack/lib/action_controller/request.rb (modified) (2 diffs)
- branches/1-2-pre-release/actionpack/test/controller/request_test.rb (modified) (3 diffs)
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/request.rb (modified) (2 diffs)
- trunk/actionpack/test/controller/request_test.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1-2-pre-release/actionpack/CHANGELOG
r5610 r5621 1 1 *1.13.0 RC1* (November 22nd, 2006) 2 3 * 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] 2 4 3 5 * Update Routing to complain when :controller is not specified by a route. Closes #6669. [Nicholas Seckar] branches/1-2-pre-release/actionpack/lib/action_controller/request.rb
r5272 r5621 14 14 end 15 15 16 # Returns the HTTP request method as a lowercase symbol (:get, for example) 16 # Returns the HTTP request method as a lowercase symbol (:get, for example). Note, HEAD is returned as :get 17 # since the two are supposedly to be functionaly equivilent for all purposes except that HEAD won't return a response 18 # body (which Rails also takes care of elsewhere). 17 19 def method 18 20 @request_method ||= (!parameters[:_method].blank? && @env['REQUEST_METHOD'] == 'POST') ? 19 21 parameters[:_method].to_s.downcase.to_sym : 20 22 @env['REQUEST_METHOD'].downcase.to_sym 21 end 22 23 # Is this a GET request? Equivalent to request.method == :get 23 24 @request_method == :head ? :get : @request_method 25 end 26 27 # Is this a GET (or HEAD) request? Equivalent to request.method == :get 24 28 def get? 25 29 method == :get … … 41 45 end 42 46 43 # Is this a HEAD request? Equivalent to request.method == :head 47 # Is this a HEAD request? HEAD is mapped as :get for request.method, so here we ask the 48 # REQUEST_METHOD header directly. Thus, for head, both get? and head? will return true. 44 49 def head? 45 method== :head50 @env['REQUEST_METHOD'].downcase.to_sym == :head 46 51 end 47 52 branches/1-2-pre-release/actionpack/test/controller/request_test.rb
r5272 r5621 275 275 276 276 def test_symbolized_request_methods 277 [: head, :get, :post, :put, :delete].each do |method|277 [:get, :post, :put, :delete].each do |method| 278 278 set_request_method_to method 279 279 assert_equal method, @request.method … … 283 283 def test_allow_method_hacking_on_post 284 284 set_request_method_to :post 285 [: head, :get, :put, :delete].each do |method|285 [:get, :put, :delete].each do |method| 286 286 @request.instance_eval { @parameters = { :_method => method } ; @request_method = nil } 287 287 assert_equal method, @request.method … … 291 291 def test_restrict_method_hacking 292 292 @request.instance_eval { @parameters = { :_method => 'put' } } 293 [: head, :get, :put, :delete].each do |method|293 [:get, :put, :delete].each do |method| 294 294 set_request_method_to method 295 295 assert_equal method, @request.method 296 296 end 297 end 298 299 def test_head_masquarading_as_get 300 set_request_method_to :head 301 assert_equal :get, @request.method 302 assert @request.get? 303 assert @request.head? 297 304 end 298 305 trunk/actionpack/CHANGELOG
r5607 r5621 1 1 *SVN* 2 3 * 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] 2 4 3 5 * Update Routing to complain when :controller is not specified by a route. Closes #6669. [Nicholas Seckar] trunk/actionpack/lib/action_controller/request.rb
r5272 r5621 14 14 end 15 15 16 # Returns the HTTP request method as a lowercase symbol (:get, for example) 16 # Returns the HTTP request method as a lowercase symbol (:get, for example). Note, HEAD is returned as :get 17 # since the two are supposedly to be functionaly equivilent for all purposes except that HEAD won't return a response 18 # body (which Rails also takes care of elsewhere). 17 19 def method 18 20 @request_method ||= (!parameters[:_method].blank? && @env['REQUEST_METHOD'] == 'POST') ? 19 21 parameters[:_method].to_s.downcase.to_sym : 20 22 @env['REQUEST_METHOD'].downcase.to_sym 21 end 22 23 # Is this a GET request? Equivalent to request.method == :get 23 24 @request_method == :head ? :get : @request_method 25 end 26 27 # Is this a GET (or HEAD) request? Equivalent to request.method == :get 24 28 def get? 25 29 method == :get … … 41 45 end 42 46 43 # Is this a HEAD request? Equivalent to request.method == :head 47 # Is this a HEAD request? HEAD is mapped as :get for request.method, so here we ask the 48 # REQUEST_METHOD header directly. Thus, for head, both get? and head? will return true. 44 49 def head? 45 method== :head50 @env['REQUEST_METHOD'].downcase.to_sym == :head 46 51 end 47 52 trunk/actionpack/test/controller/request_test.rb
r5272 r5621 275 275 276 276 def test_symbolized_request_methods 277 [: head, :get, :post, :put, :delete].each do |method|277 [:get, :post, :put, :delete].each do |method| 278 278 set_request_method_to method 279 279 assert_equal method, @request.method … … 283 283 def test_allow_method_hacking_on_post 284 284 set_request_method_to :post 285 [: head, :get, :put, :delete].each do |method|285 [:get, :put, :delete].each do |method| 286 286 @request.instance_eval { @parameters = { :_method => method } ; @request_method = nil } 287 287 assert_equal method, @request.method … … 291 291 def test_restrict_method_hacking 292 292 @request.instance_eval { @parameters = { :_method => 'put' } } 293 [: head, :get, :put, :delete].each do |method|293 [:get, :put, :delete].each do |method| 294 294 set_request_method_to method 295 295 assert_equal method, @request.method 296 296 end 297 end 298 299 def test_head_masquarading_as_get 300 set_request_method_to :head 301 assert_equal :get, @request.method 302 assert @request.get? 303 assert @request.head? 297 304 end 298 305