From 5a8a550a45c5ca7abc9785ed180d5f46189c9958 Mon Sep 17 00:00:00 2001 From: Yehuda Katz + Carl Lerche Date: Mon, 15 Jun 2009 11:21:08 -0700 Subject: Finish making things pass with updated internal content_type semantics --- actionpack/lib/action_dispatch/http/response.rb | 56 +++++-------------------- 1 file changed, 11 insertions(+), 45 deletions(-) (limited to 'actionpack/lib/action_dispatch/http') diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index b9db7a4508..e58b4b5e19 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -67,12 +67,7 @@ module ActionDispatch # :nodoc: end def body=(body) - @body = - if body.respond_to?(:to_str) - [body] - else - body - end + @body = body.respond_to?(:to_str) ? [body] : body end def body_parts @@ -96,36 +91,7 @@ module ActionDispatch # :nodoc: # If a character set has been defined for this response (see charset=) then # the character set information will also be included in the content type # information. - def content_type=(mime_type) - self.headers["Content-Type"] = - if mime_type =~ /charset/ || (c = charset).nil? - mime_type.to_s - else - "#{mime_type}; charset=#{c}" - end - end - - # Returns the response's content MIME type, or nil if content type has been set. - def content_type - content_type = String(headers["Content-Type"] || headers["type"]).split(";")[0] - content_type.blank? ? nil : content_type - end - - # Set the charset of the Content-Type header. Set to nil to remove it. - # If no content type is set, it defaults to HTML. - def charset=(charset) - headers["Content-Type"] = - if charset - "#{content_type || Mime::HTML}; charset=#{charset}" - else - content_type || Mime::HTML.to_s - end - end - - def charset - charset = String(headers["Content-Type"] || headers["type"]).split(";")[1] - charset.blank? ? nil : charset.strip.split("=")[1] - end + attr_accessor :charset, :content_type def last_modified if last = headers['Last-Modified'] @@ -162,15 +128,15 @@ module ActionDispatch # :nodoc: end def assign_default_content_type_and_charset! - if type = headers['Content-Type'] || headers['type'] - unless type =~ /charset=/ || sending_file? - headers['Content-Type'] = "#{type}; charset=#{default_charset}" - end - else - type = Mime::HTML.to_s - type += "; charset=#{default_charset}" unless sending_file? - headers['Content-Type'] = type - end + return if !headers["Content-Type"].blank? + + @content_type ||= Mime::HTML + @charset ||= default_charset + + type = @content_type.to_s.dup + type << "; charset=#{@charset}" unless sending_file? + + headers["Content-Type"] = type end def prepare! -- cgit v1.2.3