aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack
diff options
context:
space:
mode:
authorPrem Sichanugrist <s@sikac.hu>2014-02-14 15:50:08 -0500
committerPrem Sichanugrist <s@sikac.hu>2014-02-18 12:11:41 -0500
commit3047376870d4a7adc7ff15c3cb4852e073c8f1da (patch)
treeacc61fe46d2367aae107de08efe04a39beec1f12 /actionpack
parent9fe506e3944652c3681ca27d1c2a3a559f605359 (diff)
downloadrails-3047376870d4a7adc7ff15c3cb4852e073c8f1da.tar.gz
rails-3047376870d4a7adc7ff15c3cb4852e073c8f1da.tar.bz2
rails-3047376870d4a7adc7ff15c3cb4852e073c8f1da.zip
Add `#no_content_type` attribute to `AD::Response`
Setting this attribute to `true` will remove the content type header from the request. This is use in `render :body` feature.
Diffstat (limited to 'actionpack')
-rw-r--r--actionpack/lib/action_controller/metal/rack_delegation.rb4
-rw-r--r--actionpack/lib/action_controller/metal/rendering.rb10
-rw-r--r--actionpack/lib/action_dispatch/http/response.rb15
-rw-r--r--actionpack/test/dispatch/response_test.rb2
4 files changed, 20 insertions, 11 deletions
diff --git a/actionpack/lib/action_controller/metal/rack_delegation.rb b/actionpack/lib/action_controller/metal/rack_delegation.rb
index bdf6e88699..e1bee9e60c 100644
--- a/actionpack/lib/action_controller/metal/rack_delegation.rb
+++ b/actionpack/lib/action_controller/metal/rack_delegation.rb
@@ -5,8 +5,8 @@ module ActionController
module RackDelegation
extend ActiveSupport::Concern
- delegate :headers, :status=, :location=, :content_type=,
- :status, :location, :content_type, :to => "@_response"
+ delegate :headers, :status=, :location=, :content_type=, :no_content_type=,
+ :status, :location, :content_type, :no_content_type, :to => "@_response"
def dispatch(action, request)
set_response!(request)
diff --git a/actionpack/lib/action_controller/metal/rendering.rb b/actionpack/lib/action_controller/metal/rendering.rb
index ce37eaefd8..3c4ef596c7 100644
--- a/actionpack/lib/action_controller/metal/rendering.rb
+++ b/actionpack/lib/action_controller/metal/rendering.rb
@@ -44,15 +44,13 @@ module ActionController
def _process_format(format, options = {})
super
- self.content_type ||= format.to_s
- if options[:body].present?
- self.content_type = "none"
+ if options[:body]
self.headers.delete "Content-Type"
- end
-
- if options[:plain].present?
+ elsif options[:plain]
self.content_type = Mime::TEXT
+ else
+ self.content_type ||= format.to_s
end
end
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb
index 15a177aaff..f14ca1ea44 100644
--- a/actionpack/lib/action_dispatch/http/response.rb
+++ b/actionpack/lib/action_dispatch/http/response.rb
@@ -63,6 +63,8 @@ module ActionDispatch # :nodoc:
# content you're giving them, so we need to send that along.
attr_accessor :charset
+ attr_accessor :no_content_type # :nodoc:
+
CONTENT_TYPE = "Content-Type".freeze
SET_COOKIE = "Set-Cookie".freeze
LOCATION = "Location".freeze
@@ -288,7 +290,7 @@ module ActionDispatch # :nodoc:
end
def assign_default_content_type_and_charset!(headers)
- return if headers[CONTENT_TYPE].present? || @content_type == "none"
+ return if headers[CONTENT_TYPE].present?
@content_type ||= Mime::HTML
@charset ||= self.class.default_charset unless @charset == false
@@ -303,8 +305,17 @@ module ActionDispatch # :nodoc:
!@sending_file && @charset != false
end
+ def remove_content_type!
+ headers.delete CONTENT_TYPE
+ end
+
def rack_response(status, header)
- assign_default_content_type_and_charset!(header)
+ if no_content_type
+ remove_content_type!
+ else
+ assign_default_content_type_and_charset!(header)
+ end
+
handle_conditional_get!
header[SET_COOKIE] = header[SET_COOKIE].join("\n") if header[SET_COOKIE].respond_to?(:join)
diff --git a/actionpack/test/dispatch/response_test.rb b/actionpack/test/dispatch/response_test.rb
index 26b77dfaf7..1360ede3f8 100644
--- a/actionpack/test/dispatch/response_test.rb
+++ b/actionpack/test/dispatch/response_test.rb
@@ -238,7 +238,7 @@ class ResponseTest < ActiveSupport::TestCase
test "does not add default content-type if Content-Type is none" do
resp = ActionDispatch::Response.new.tap { |response|
- response.content_type = 'none'
+ response.no_content_type = true
}
assert_not resp.headers.has_key?('Content-Type')