diff options
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/http/response.rb | 22 |
1 files changed, 15 insertions, 7 deletions
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index 4aee489912..e841db77b6 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -136,20 +136,28 @@ module ActionDispatch # :nodoc: @committed = false @sending = false @sent = false - @content_type = nil - @charset = self.class.default_charset - if content_type = self[CONTENT_TYPE] - type, charset = content_type.split(/;\s*charset=/) - @content_type = Mime::Type.lookup(type) - @charset = charset || self.class.default_charset - end + content_type = parse_content_type self[CONTENT_TYPE] + @content_type = content_type.mime_type + @charset = content_type.charset prepare_cache_control! yield self if block_given? end + ContentTypeHeader = Struct.new :mime_type, :charset + + def parse_content_type(content_type) + if content_type + type, charset = content_type.split(/;\s*charset=/) + ContentTypeHeader.new(Mime::Type.lookup(type), + charset || self.class.default_charset) + else + ContentTypeHeader.new(nil, self.class.default_charset) + end + end + def have_header?(key); headers.key? key; end def get_header(key); headers[key]; end def set_header(key, v); headers[key] = v; end |