Permalink
Browse files

Construct a single HeaderHash. Speed up assign_default_content_type_a…

…nd_charset
  • Loading branch information...
1 parent bdb61c1 commit b1d4fb71bf890793133fab8e4226952865fd468b @jeremy jeremy committed May 25, 2009
Showing with 10 additions and 4 deletions.
  1. +10 −4 actionpack/lib/action_dispatch/http/response.rb
@@ -41,8 +41,7 @@ class Response < Rack::Response
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 @@ def sending_file?
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!

0 comments on commit b1d4fb7

Please sign in to comment.