diff options
author | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2014-12-31 16:52:27 -0200 |
---|---|---|
committer | Carlos Antonio da Silva <carlosantoniodasilva@gmail.com> | 2014-12-31 16:52:27 -0200 |
commit | 777c45e6a5a2cb89e1e1e892a32b0dbdebbfe680 (patch) | |
tree | 9e84973c1bbd55ec44aeb8a56d5bdbc2459acc53 | |
parent | ae08bef428827e8da4b00088b273de11b5190aed (diff) | |
parent | 7ef7f1cc152a4b180dd455ffa859bf11d1daeda0 (diff) | |
download | rails-777c45e6a5a2cb89e1e1e892a32b0dbdebbfe680.tar.gz rails-777c45e6a5a2cb89e1e1e892a32b0dbdebbfe680.tar.bz2 rails-777c45e6a5a2cb89e1e1e892a32b0dbdebbfe680.zip |
Merge pull request #18275 from robin850/head-status
Correctly use the response's status code calling head
-rw-r--r-- | actionpack/CHANGELOG.md | 4 | ||||
-rw-r--r-- | actionpack/lib/action_controller/metal.rb | 5 | ||||
-rw-r--r-- | actionpack/lib/action_controller/metal/head.rb | 2 | ||||
-rw-r--r-- | actionpack/test/controller/render_test.rb | 17 |
4 files changed, 23 insertions, 5 deletions
diff --git a/actionpack/CHANGELOG.md b/actionpack/CHANGELOG.md index b5380a46e8..3f29d810d5 100644 --- a/actionpack/CHANGELOG.md +++ b/actionpack/CHANGELOG.md @@ -1,3 +1,7 @@ +* Correctly rely on the response's status code to handle calls to `head`. + + *Robin Dupret* + * Using `head` method returns empty response_body instead of returning a single space " ". diff --git a/actionpack/lib/action_controller/metal.rb b/actionpack/lib/action_controller/metal.rb index 6dd213b2f7..993f8e150d 100644 --- a/actionpack/lib/action_controller/metal.rb +++ b/actionpack/lib/action_controller/metal.rb @@ -173,6 +173,7 @@ module ActionController def status @_status end + alias :response_code :status # :nodoc: def status=(status) @_status = Rack::Utils.status_code(status) @@ -236,9 +237,5 @@ module ActionController lambda { |env| new.dispatch(name, klass.new(env)) } end end - - def _status_code #:nodoc: - @_status - end end end diff --git a/actionpack/lib/action_controller/metal/head.rb b/actionpack/lib/action_controller/metal/head.rb index 57e60222cd..0d93e2f7aa 100644 --- a/actionpack/lib/action_controller/metal/head.rb +++ b/actionpack/lib/action_controller/metal/head.rb @@ -31,7 +31,7 @@ module ActionController self.response_body = "" - if include_content?(self._status_code) + if include_content?(self.response_code) self.content_type = content_type || (Mime[formats.first] if formats) self.response.charset = false if self.response else diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index b036b6c08e..929b161eb6 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -217,6 +217,15 @@ class TestController < ActionController::Base head :forbidden, :x_custom_header => "something" end + def head_with_no_content + # Fill in the headers with dummy data to make + # sure they get removed during the testing + response.headers["Content-Type"] = "dummy" + response.headers["Content-Length"] = 42 + + head 204 + end + private def set_variable_for_layout @@ -545,6 +554,14 @@ class HeadRenderTest < ActionController::TestCase end end + def test_head_with_no_content + get :head_with_no_content + + assert_equal 204, @response.status + assert_nil @response.headers["Content-Type"] + assert_nil @response.headers["Content-Length"] + end + def test_head_with_string_status get :head_with_string_status, :status => "404 Eat Dirt" assert_equal 404, @response.response_code |