aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/http/response.rb
diff options
context:
space:
mode:
authorJon Moss <me@jonathanmoss.me>2016-08-29 17:34:39 -0400
committerJon Moss <me@jonathanmoss.me>2016-08-29 17:50:48 -0400
commita960fc703245df735787a3fcc05eb66701e150ba (patch)
tree2074dbab1843912a4d2cdb8d4bb9c0085fa7c63e /actionpack/lib/action_dispatch/http/response.rb
parent60f34fd7ef08e507e765c6df3fa1664b22e851e6 (diff)
downloadrails-a960fc703245df735787a3fcc05eb66701e150ba.tar.gz
rails-a960fc703245df735787a3fcc05eb66701e150ba.tar.bz2
rails-a960fc703245df735787a3fcc05eb66701e150ba.zip
Allow `send_file` to declare a charset
Removed my patch in favor of @tenderlove's less invasive approach. [Aaron Patterson & Jon Moss]
Diffstat (limited to 'actionpack/lib/action_dispatch/http/response.rb')
-rw-r--r--actionpack/lib/action_dispatch/http/response.rb9
1 files changed, 5 insertions, 4 deletions
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb
index 9788431943..c8f0644ef5 100644
--- a/actionpack/lib/action_dispatch/http/response.rb
+++ b/actionpack/lib/action_dispatch/http/response.rb
@@ -224,8 +224,10 @@ module ActionDispatch # :nodoc:
# Sets the HTTP content type.
def content_type=(content_type)
- header_info = parse_content_type
- set_content_type content_type.to_s, header_info.charset || self.class.default_charset
+ return unless content_type
+ new_header_info = parse_content_type(content_type.to_s)
+ prev_header_info = parse_content_type(get_header(CONTENT_TYPE))
+ set_content_type new_header_info.mime_type, new_header_info.charset || prev_header_info.charset || self.class.default_charset
end
# Sets the HTTP response's content MIME type. For example, in the controller
@@ -403,8 +405,7 @@ module ActionDispatch # :nodoc:
ContentTypeHeader = Struct.new :mime_type, :charset
NullContentTypeHeader = ContentTypeHeader.new nil, nil
- def parse_content_type
- content_type = get_header CONTENT_TYPE
+ def parse_content_type(content_type = get_header(CONTENT_TYPE))
if content_type
type, charset = content_type.split(/;\s*charset=/)
type = nil if type.empty?