diff options
author | José Valim <jose.valim@gmail.com> | 2010-01-16 13:17:03 +0100 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2010-01-16 15:45:07 +0100 |
commit | 92f49b5f1ebf42514c58e1fda87c0b8a1b33d08f (patch) | |
tree | 860e27b214bbb5e03ea235eae32558ba6fb23515 /actionpack/lib/action_dispatch/http/response.rb | |
parent | 5a52523a800c8a57d1ad80ad3a0ba81711cce38e (diff) | |
download | rails-92f49b5f1ebf42514c58e1fda87c0b8a1b33d08f.tar.gz rails-92f49b5f1ebf42514c58e1fda87c0b8a1b33d08f.tar.bz2 rails-92f49b5f1ebf42514c58e1fda87c0b8a1b33d08f.zip |
Split ActionDispatch http in smaller chunks.
Diffstat (limited to 'actionpack/lib/action_dispatch/http/response.rb')
-rw-r--r-- | actionpack/lib/action_dispatch/http/response.rb | 80 |
1 files changed, 2 insertions, 78 deletions
diff --git a/actionpack/lib/action_dispatch/http/response.rb b/actionpack/lib/action_dispatch/http/response.rb index 8524bbd993..65df9b1f03 100644 --- a/actionpack/lib/action_dispatch/http/response.rb +++ b/actionpack/lib/action_dispatch/http/response.rb @@ -32,6 +32,8 @@ module ActionDispatch # :nodoc: # end # end class Response < Rack::Response + include ActionDispatch::Http::Cache::Response + attr_accessor :request, :blank attr_writer :header, :sending_file @@ -55,10 +57,6 @@ module ActionDispatch # :nodoc: yield self if block_given? end - def cache_control - @cache_control ||= {} - end - def status=(status) @status = Rack::Utils.status_code(status) end @@ -114,33 +112,6 @@ module ActionDispatch # :nodoc: # information. attr_accessor :charset, :content_type - def last_modified - if last = headers['Last-Modified'] - Time.httpdate(last) - end - end - - def last_modified? - headers.include?('Last-Modified') - end - - def last_modified=(utc_time) - headers['Last-Modified'] = utc_time.httpdate - end - - def etag - @etag - end - - def etag? - @etag - end - - def etag=(etag) - key = ActiveSupport::Cache.expand_cache_key(etag) - @etag = %("#{Digest::MD5.hexdigest(key)}") - end - CONTENT_TYPE = "Content-Type" cattr_accessor(:default_charset) { "utf-8" } @@ -222,31 +193,6 @@ module ActionDispatch # :nodoc: end private - def handle_conditional_get! - if etag? || last_modified? || !@cache_control.empty? - set_conditional_cache_control! - elsif nonempty_ok_response? - self.etag = @body - - if request && request.etag_matches?(etag) - self.status = 304 - self.body = [] - end - - set_conditional_cache_control! - else - headers["Cache-Control"] = "no-cache" - end - end - - def nonempty_ok_response? - @status == 200 && string_body? - end - - def string_body? - !@blank && @body.respond_to?(:all?) && @body.all? { |part| part.is_a?(String) } - end - def assign_default_content_type_and_charset! return if headers[CONTENT_TYPE].present? @@ -259,27 +205,5 @@ module ActionDispatch # :nodoc: headers[CONTENT_TYPE] = type end - DEFAULT_CACHE_CONTROL = "max-age=0, private, must-revalidate" - - def set_conditional_cache_control! - control = @cache_control - - if control.empty? - headers["Cache-Control"] = DEFAULT_CACHE_CONTROL - elsif @cache_control[:no_cache] - headers["Cache-Control"] = "no-cache" - else - extras = control[:extras] - max_age = control[:max_age] - - options = [] - options << "max-age=#{max_age.to_i}" if max_age - options << (control[:public] ? "public" : "private") - options << "must-revalidate" if control[:must_revalidate] - options.concat(extras) if extras - - headers["Cache-Control"] = options.join(", ") - end - end end end |