aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/http/cache.rb
diff options
context:
space:
mode:
authorCarlhuda <carlhuda@engineyard.com>2010-02-19 19:19:20 -0800
committerCarlhuda <carlhuda@engineyard.com>2010-02-19 19:19:20 -0800
commita3c6ad7d5e567cf4d688147357c5de134763599d (patch)
tree9f17a4cdc3b24a6f316e94617aeb5a2bf57ff55f /actionpack/lib/action_dispatch/http/cache.rb
parentbf8898b49b5a8c03d328bde7b6ee30edb02d873b (diff)
downloadrails-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/cache.rb')
-rw-r--r--actionpack/lib/action_dispatch/http/cache.rb21
1 files changed, 18 insertions, 3 deletions
diff --git a/actionpack/lib/action_dispatch/http/cache.rb b/actionpack/lib/action_dispatch/http/cache.rb
index 428e62dc6b..d2404e63c5 100644
--- a/actionpack/lib/action_dispatch/http/cache.rb
+++ b/actionpack/lib/action_dispatch/http/cache.rb
@@ -37,8 +37,21 @@ module ActionDispatch
end
module Response
- def cache_control
- @cache_control ||= {}
+ attr_reader :cache_control
+
+ def initialize(*)
+ status, header, body = super
+
+ @cache_control = {}
+ @etag = self["ETag"]
+
+ if cache_control = self["Cache-Control"]
+ cache_control.split(/,\s*/).each do |segment|
+ first, last = segment.split("=")
+ last ||= true
+ @cache_control[first.to_sym] = last
+ end
+ end
end
def last_modified
@@ -65,7 +78,7 @@ module ActionDispatch
def etag=(etag)
key = ActiveSupport::Cache.expand_cache_key(etag)
- @etag = %("#{Digest::MD5.hexdigest(key)}")
+ @etag = self["ETag"] = %("#{Digest::MD5.hexdigest(key)}")
end
private
@@ -100,6 +113,8 @@ module ActionDispatch
def set_conditional_cache_control!
control = @cache_control
+ return if self["Cache-Control"].present?
+
if control.empty?
headers["Cache-Control"] = DEFAULT_CACHE_CONTROL
elsif @cache_control[:no_cache]