diff options
author | José Valim <jose.valim@gmail.com> | 2012-05-08 00:52:31 -0700 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2012-05-08 00:52:31 -0700 |
commit | fc5c41e9424e49db77245de4d17031ebb3e96b5c (patch) | |
tree | 880ef8d0ade5b0ec39ff0cf04057758ab77df8a4 | |
parent | c52ba1b372be08b46fd94deaf1ff382463785c7f (diff) | |
parent | c09a92fb9e08ee36d795a237899d3439930ef784 (diff) | |
download | rails-fc5c41e9424e49db77245de4d17031ebb3e96b5c.tar.gz rails-fc5c41e9424e49db77245de4d17031ebb3e96b5c.tar.bz2 rails-fc5c41e9424e49db77245de4d17031ebb3e96b5c.zip |
Merge pull request #6201 from whistlerbrk/master
Allow explicitly set content-type via head method when status code allows it according to the RFCs
-rw-r--r-- | actionpack/lib/action_controller/metal/head.rb | 3 | ||||
-rw-r--r-- | actionpack/test/controller/render_test.rb | 21 |
2 files changed, 23 insertions, 1 deletions
diff --git a/actionpack/lib/action_controller/metal/head.rb b/actionpack/lib/action_controller/metal/head.rb index 5bdbde9ebb..2fcd933d32 100644 --- a/actionpack/lib/action_controller/metal/head.rb +++ b/actionpack/lib/action_controller/metal/head.rb @@ -20,6 +20,7 @@ module ActionController options, status = status, nil if status.is_a?(Hash) status ||= options.delete(:status) || :ok location = options.delete(:location) + content_type = options.delete(:content_type) options.each do |key, value| headers[key.to_s.dasherize.split('-').each { |v| v[0] = v[0].chr.upcase }.join('-')] = value.to_s @@ -29,7 +30,7 @@ module ActionController self.location = url_for(location) if location if include_content_headers?(self.status) - self.content_type = Mime[formats.first] if formats + self.content_type = content_type || (Mime[formats.first] if formats) else headers.delete('Content-Type') headers.delete('Content-Length') diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 5e699c0daf..3d58c02338 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -505,6 +505,14 @@ class TestController < ActionController::Base render :text => "hello world!" end + def head_created + head :created + end + + def head_created_with_application_json_content_type + head :created, :content_type => "application/json" + end + def head_with_location_header head :location => "/foo" end @@ -1177,6 +1185,19 @@ class RenderTest < ActionController::TestCase assert_equal "<html>\n <p>Hello</p>\n</html>\n", @response.body end + def test_head_created + post :head_created + assert_blank @response.body + assert_response :created + end + + def test_head_created_with_application_json_content_type + post :head_created_with_application_json_content_type + assert_blank @response.body + assert_equal "application/json", @response.content_type + assert_response :created + end + def test_head_with_location_header get :head_with_location_header assert_blank @response.body |