aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/http/response.rb
diff options
context:
space:
mode:
authorYuji Yaginuma <yuuji.yaginuma@gmail.com>2019-06-21 09:04:30 +0900
committerGitHub <noreply@github.com>2019-06-21 09:04:30 +0900
commitc631e8d011a7cf3e7ade4e9e8db56d2b89bd530c (patch)
treece404d935851ec89e426e7538067276cc5a7e885 /actionpack/lib/action_dispatch/http/response.rb
parent3218459c28737071fe4424cd375c1b06a5c317df (diff)
parentddb6d788d6a611fd1ba6cf92ad6d1342079517a8 (diff)
downloadrails-c631e8d011a7cf3e7ade4e9e8db56d2b89bd530c.tar.gz
rails-c631e8d011a7cf3e7ade4e9e8db56d2b89bd530c.tar.bz2
rails-c631e8d011a7cf3e7ade4e9e8db56d2b89bd530c.zip
Merge pull request #36490 from y-yagi/revise_36034
Make `ActionDispatch::Response#content_type` behavior configurable
Diffstat (limited to 'actionpack/lib/action_dispatch/http/response.rb')
-rw-r--r--actionpack/lib/action_dispatch/http/response.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb
index 63d8f6b585..ea3692951f 100644
--- a/actionpack/lib/action_dispatch/http/response.rb
+++ b/actionpack/lib/action_dispatch/http/response.rb
@@ -86,6 +86,7 @@ module ActionDispatch # :nodoc:
cattr_accessor :default_charset, default: "utf-8"
cattr_accessor :default_headers
+ cattr_accessor :return_only_media_type_on_content_type, default: false
include Rack::Response::Helpers
# Aliasing these off because AD::Http::Cache::Response defines them.
@@ -243,7 +244,17 @@ module ActionDispatch # :nodoc:
# Content type of response.
def content_type
- super.presence
+ if self.class.return_only_media_type_on_content_type
+ ActiveSupport::Deprecation.warn(
+ "Rails 6.1 will return Content-Type header without modification." \
+ " If you want just the MIME type, please use `#media_type` instead."
+ )
+
+ content_type = super
+ content_type ? content_type.split(/;\s*charset=/)[0].presence : content_type
+ else
+ super.presence
+ end
end
# Media type of response.