diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-06-15 16:09:44 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-06-15 16:09:44 -0700 |
commit | dd8c76d9b90da5c1b551e26c7d27d9519a19b711 (patch) | |
tree | abdc222572037cda0974bfbf46700629496038a1 /actionpack/lib/action_dispatch | |
parent | 57941f01d52b7d2286629c3e04cbee23006584ff (diff) | |
download | rails-dd8c76d9b90da5c1b551e26c7d27d9519a19b711.tar.gz rails-dd8c76d9b90da5c1b551e26c7d27d9519a19b711.tar.bz2 rails-dd8c76d9b90da5c1b551e26c7d27d9519a19b711.zip |
set the default charset in response initialize
this way we don't have to mutate the instance (as much) when writing a
rack response
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/http/response.rb | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index 9e53a0f08b..ea60907c09 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -61,7 +61,7 @@ module ActionDispatch # :nodoc: # The charset of the response. HTML wants to know the encoding of the # content you're giving them, so we need to send that along. - attr_accessor :charset + attr_reader :charset CONTENT_TYPE = "Content-Type".freeze SET_COOKIE = "Set-Cookie".freeze @@ -127,7 +127,7 @@ module ActionDispatch # :nodoc: @sending = false @sent = false @content_type = nil - @charset = nil + @charset = self.class.default_charset if content_type = self[CONTENT_TYPE] type, charset = content_type.split(/;\s*charset=/) @@ -187,6 +187,15 @@ module ActionDispatch # :nodoc: @content_type = content_type.to_s end + # Sets the HTTP character set. + def charset=(charset) + if nil == charset + @charset = self.class.default_charset + else + @charset = charset + end + end + # The response code of the request. def response_code @status @@ -323,10 +332,9 @@ module ActionDispatch # :nodoc: return if headers[CONTENT_TYPE].present? @content_type ||= Mime::HTML - @charset ||= self.class.default_charset unless @charset == false type = @content_type.to_s.dup - type << "; charset=#{@charset}" if append_charset? + type << "; charset=#{charset}" if append_charset? headers[CONTENT_TYPE] = type end |