diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG
index e0b667969c..fd15879424 100644
--- a/actionpack/CHANGELOG
+++ b/actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* render :xml and :json preserve custom content types. #10388 [jmettraux, Chu Yeow]
+
* Refactor Action View template handlers. #10437 [Josh Peek]
* Fix DoubleRenderError message and leave out mention of returning false from filters. Closes #10380 [fcheung]
diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index b5c4780f52..f1d416d664 100755
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -873,13 +873,13 @@ module ActionController #:nodoc:
end
elsif xml = options[:xml]
- response.content_type = Mime::XML
+ response.content_type ||= Mime::XML
render_for_text(xml.respond_to?(:to_xml) ? xml.to_xml : xml, options[:status])
elsif json = options[:json]
json = json.to_json unless json.is_a?(String)
json = "#{options[:callback]}(#{json})" unless options[:callback].blank?
- response.content_type = Mime::JSON
+ response.content_type ||= Mime::JSON
render_for_text(json, options[:status])
elsif partial = options[:partial]
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index 7765c62a5e..d3a9ec195c 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -44,6 +44,10 @@ class TestController < ActionController::Base
render :json => {:hello => 'world'}.to_json, :callback => 'alert'
end
+ def render_json_with_custom_content_type
+ render :json => {:hello => 'world'}.to_json, :content_type => 'text/javascript'
+ end
+
def render_symbol_json
render :json => {:hello => 'world'}.to_json
end
@@ -65,6 +69,10 @@ class TestController < ActionController::Base
render :template => "test/hello"
end
+ def render_xml_with_custom_content_type
+ render :xml => "
Hello David
\nThis is grand!
\n\n", @response.body + assert_equal "application/xml", @response.content_type end def test_render_xml_with_default @@ -435,6 +450,11 @@ class RenderTest < Test::Unit::TestCase assert_equal %(Element.replace("foo", "partial html");), @response.body end + def test_should_render_xml_but_keep_custom_content_type + get :render_xml_with_custom_content_type + assert_equal "application/atomsvc+xml", @response.content_type + end + protected def etag_for(text)