From 964b2826c44888a310488fd3ce297b68e1dbf670 Mon Sep 17 00:00:00 2001 From: arvida Date: Mon, 31 Oct 2011 10:26:05 +0100 Subject: Added accessor methods for Date header --- actionpack/lib/action_dispatch/http/cache.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/http/cache.rb b/actionpack/lib/action_dispatch/http/cache.rb index aaed0d750f..7d83ecb058 100644 --- a/actionpack/lib/action_dispatch/http/cache.rb +++ b/actionpack/lib/action_dispatch/http/cache.rb @@ -56,6 +56,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)}") -- cgit v1.2.3 From 2a7230aa997b19971b39812893d79ca3f6c3bb47 Mon Sep 17 00:00:00 2001 From: arvida Date: Mon, 31 Oct 2011 10:27:23 +0100 Subject: Ensuring a HTTP Date header when setting Cache-Control's max-age with #expires_in --- actionpack/lib/action_controller/metal/conditional_get.rb | 3 +++ 1 file changed, 3 insertions(+) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_controller/metal/conditional_get.rb b/actionpack/lib/action_controller/metal/conditional_get.rb index a5e37172c9..809894395d 100644 --- a/actionpack/lib/action_controller/metal/conditional_get.rb +++ b/actionpack/lib/action_controller/metal/conditional_get.rb @@ -70,11 +70,14 @@ 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, :public => options.delete(:public)) 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 no-cache so no caching should occur by the browser or -- cgit v1.2.3