aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorPrem Sichanugrist <s@sikac.hu>2014-01-31 15:37:58 -0500
committerPrem Sichanugrist <s@sikac.hu>2014-02-18 12:08:36 -0500
commit103e18c87d50a53cd0a33b4e03f2c8a8eff19ece (patch)
tree07f0d46e80ea3dd978e4a6ca3e533087d76ca7f8 /actionpack/lib
parent6c496a6d2a21fb8f6f5fb4a97acf1f2de828d1d5 (diff)
downloadrails-103e18c87d50a53cd0a33b4e03f2c8a8eff19ece.tar.gz
rails-103e18c87d50a53cd0a33b4e03f2c8a8eff19ece.tar.bz2
rails-103e18c87d50a53cd0a33b4e03f2c8a8eff19ece.zip
Introduce `render :body` for render raw content
This is an option for sending a raw content back to browser. Note that this rendering option will unset the default content type and does not include "Content-Type" header back in the response. You should only use this option if you are expecting the "Content-Type" header to not be set. More information on "Content-Type" header can be found on RFC 2616, section 7.2.1. Please see #12374 for more detail.
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/abstract_controller/rendering.rb4
-rw-r--r--actionpack/lib/action_controller/metal/rendering.rb17
-rw-r--r--actionpack/lib/action_dispatch/http/response.rb2
3 files changed, 16 insertions, 7 deletions
diff --git a/actionpack/lib/abstract_controller/rendering.rb b/actionpack/lib/abstract_controller/rendering.rb
index f24b03ad16..349bbf4ee7 100644
--- a/actionpack/lib/abstract_controller/rendering.rb
+++ b/actionpack/lib/abstract_controller/rendering.rb
@@ -23,7 +23,7 @@ module AbstractController
def render(*args, &block)
options = _normalize_render(*args, &block)
self.response_body = render_to_body(options)
- _process_format(rendered_format) if rendered_format
+ _process_format(rendered_format, options) if rendered_format
self.response_body
end
@@ -98,7 +98,7 @@ module AbstractController
# Process the rendered format.
# :api: private
- def _process_format(format)
+ def _process_format(format, options = {})
end
# Normalize args and options.
diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb
index 5c48b4ab98..c9ae1ab388 100644
--- a/actionpack/lib/action_controller/metal/rendering.rb
+++ b/actionpack/lib/action_controller/metal/rendering.rb
@@ -27,14 +27,19 @@ module ActionController
end
def render_to_body(options = {})
- super || options[:text].presence || ' '
+ super || options[:body].presence || options[:text].presence || ' '
end
private
- def _process_format(format)
+ def _process_format(format, options = {})
super
self.content_type ||= format.to_s
+
+ if options[:body].present?
+ self.content_type = "none"
+ self.headers.delete "Content-Type"
+ end
end
# Normalize arguments by catching blocks and setting them on :update.
@@ -46,12 +51,16 @@ module ActionController
# Normalize both text and status options.
def _normalize_options(options) #:nodoc:
+ if options.key?(:body) && options[:body].respond_to?(:to_text)
+ options[:body] = options[:body].to_text
+ end
+
if options.key?(:text) && options[:text].respond_to?(:to_text)
options[:text] = options[:text].to_text
end
- if options.delete(:nothing) || (options.key?(:text) && options[:text].nil?)
- options[:text] = " "
+ if options.delete(:nothing) || (options.key?(:body) && options[:body].nil?) || (options.key?(:text) && options[:text].nil?)
+ options[:body] = " "
end
if options[:status]
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb
index 2c6bcf7b7b..15a177aaff 100644
--- a/actionpack/lib/action_dispatch/http/response.rb
+++ b/actionpack/lib/action_dispatch/http/response.rb
@@ -288,7 +288,7 @@ module ActionDispatch # :nodoc:
end
def assign_default_content_type_and_charset!(headers)
- return if headers[CONTENT_TYPE].present?
+ return if headers[CONTENT_TYPE].present? || @content_type == "none"
@content_type ||= Mime::HTML
@charset ||= self.class.default_charset unless @charset == false