aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@plataformatec.com.br>2012-02-18 00:28:23 -0800
committerJosé Valim <jose.valim@plataformatec.com.br>2012-02-18 00:28:23 -0800
commit2f689d462d8e94365724c5575b14ab997e11bb43 (patch)
treef6c842c996c6526c8cefd828af724fe69401f94c /actionpack/lib
parent663c9f30c60d4082cbcb77db80d809ee512e06c2 (diff)
parent2a7230aa997b19971b39812893d79ca3f6c3bb47 (diff)
downloadrails-2f689d462d8e94365724c5575b14ab997e11bb43.tar.gz
rails-2f689d462d8e94365724c5575b14ab997e11bb43.tar.bz2
rails-2f689d462d8e94365724c5575b14ab997e11bb43.zip
Merge pull request #3479 from arvida/ensure-date-header-on-expires-in
Ensure Date header on expires_in
Diffstat (limited to 'actionpack/lib')
-rw-r--r--actionpack/lib/action_controller/metal/conditional_get.rb3
-rw-r--r--actionpack/lib/action_dispatch/http/cache.rb14
2 files changed, 17 insertions, 0 deletions
diff --git a/actionpack/lib/action_controller/metal/conditional_get.rb b/actionpack/lib/action_controller/metal/conditional_get.rb
index 41758d99e8..2a8e4c575e 100644
--- a/actionpack/lib/action_controller/metal/conditional_get.rb
+++ b/actionpack/lib/action_controller/metal/conditional_get.rb
@@ -115,6 +115,8 @@ module ActionController
#
# This method will overwrite an existing Cache-Control header.
# See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html for more possibilities.
+ #
+ # The method will also ensure a HTTP Date header for client compatibility.
def expires_in(seconds, options = {}) #:doc:
response.cache_control.merge!(
:max_age => seconds,
@@ -124,6 +126,7 @@ module ActionController
options.delete(:private)
response.cache_control[:extras] = options.map {|k,v| "#{k}=#{v}"}
+ response.date = Time.now unless response.date?
end
# Sets a HTTP 1.1 Cache-Control header of <tt>no-cache</tt> so no caching should occur by the browser or
diff --git a/actionpack/lib/action_dispatch/http/cache.rb b/actionpack/lib/action_dispatch/http/cache.rb
index bea62b94d2..5ee4c044ea 100644
--- a/actionpack/lib/action_dispatch/http/cache.rb
+++ b/actionpack/lib/action_dispatch/http/cache.rb
@@ -60,6 +60,20 @@ module ActionDispatch
headers[LAST_MODIFIED] = utc_time.httpdate
end
+ def date
+ if date_header = headers['Date']
+ Time.httpdate(date_header)
+ end
+ end
+
+ def date?
+ headers.include?('Date')
+ end
+
+ def date=(utc_time)
+ headers['Date'] = utc_time.httpdate
+ end
+
def etag=(etag)
key = ActiveSupport::Cache.expand_cache_key(etag)
@etag = self[ETAG] = %("#{Digest::MD5.hexdigest(key)}")