From b1d4fb71bf890793133fab8e4226952865fd468b Mon Sep 17 00:00:00 2001 From: Jeremy Kemper Date: Sun, 24 May 2009 17:35:49 -0700 Subject: Construct a single HeaderHash. Speed up assign_default_content_type_and_charset --- actionpack/lib/action_dispatch/http/response.rb | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index edb522ff49..a01114b730 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -41,8 +41,7 @@ module ActionDispatch # :nodoc: delegate :default_charset, :to => 'ActionController::Base' def initialize - super - @header = Rack::Utils::HeaderHash.new(DEFAULT_HEADERS) + super([], 200, DEFAULT_HEADERS) end # The response code of the request @@ -162,8 +161,15 @@ module ActionDispatch # :nodoc: end def assign_default_content_type_and_charset! - self.content_type ||= Mime::HTML - self.charset ||= default_charset unless sending_file? + if type = headers['Content-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 end def prepare! -- cgit v1.2.3