diff options
author | Carlhuda <carlhuda@engineyard.com> | 2010-02-19 19:19:20 -0800 |
---|---|---|
committer | Carlhuda <carlhuda@engineyard.com> | 2010-02-19 19:19:20 -0800 |
commit | a3c6ad7d5e567cf4d688147357c5de134763599d (patch) | |
tree | 9f17a4cdc3b24a6f316e94617aeb5a2bf57ff55f /actionpack/lib/action_dispatch/http/response.rb | |
parent | bf8898b49b5a8c03d328bde7b6ee30edb02d873b (diff) | |
download | rails-a3c6ad7d5e567cf4d688147357c5de134763599d.tar.gz rails-a3c6ad7d5e567cf4d688147357c5de134763599d.tar.bz2 rails-a3c6ad7d5e567cf4d688147357c5de134763599d.zip |
Fix a bunch of pending tests by providing an introspection mode for the Response object that does up-front parsing of the headers to populate things like @etag
Diffstat (limited to 'actionpack/lib/action_dispatch/http/response.rb')
-rw-r--r-- | actionpack/lib/action_dispatch/http/response.rb | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index f299306ff4..1b8dd9abfd 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -32,31 +32,37 @@ module ActionDispatch # :nodoc: # end # end class Response < Rack::Response - include ActionDispatch::Http::Cache::Response - attr_accessor :request, :blank attr_writer :header, :sending_file alias_method :headers=, :header= - def initialize - @status = 200 - @header = {} - @cache_control = {} + module Setup + def initialize(status = 200, header = {}, body = []) + @writer = lambda { |x| @body << x } + @block = nil + @length = 0 - @writer = lambda { |x| @body << x } - @block = nil - @length = 0 + @status, @header, @body = status, header, body - @body, @cookie = [], [] - @sending_file = false + @cookie = [] + @sending_file = false - @blank = false - @etag = nil + @blank = false + + if content_type = self["Content-Type"] + type, charset = content_type.split(/;\s*charset=/) + @content_type = Mime::Type.lookup(type) + @charset = charset || "UTF-8" + end - yield self if block_given? + yield self if block_given? + end end + include Setup + include ActionDispatch::Http::Cache::Response + def status=(status) @status = Rack::Utils.status_code(status) end @@ -120,7 +126,7 @@ module ActionDispatch # :nodoc: assign_default_content_type_and_charset! handle_conditional_get! self["Set-Cookie"] = @cookie.join("\n") unless @cookie.blank? - self["ETag"] = @etag if @etag + self["ETag"] = @_etag if @_etag super end |