From 1877d096fd18629a7bc01f86ed5963328120e693 Mon Sep 17 00:00:00 2001 From: Denis Odorcic Date: Sun, 14 Mar 2010 06:12:14 -0400 Subject: [PATCH] Handle case where expires_now sets Cache-Control to 'no-cache', and should not be overridden by 'private, max-age=0, must-revalidate' --- actionpack/lib/action_controller/base.rb | 4 +++- actionpack/lib/action_controller/response.rb | 6 +++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb index 62f4395..d5f387e 100644 --- a/actionpack/lib/action_controller/base.rb +++ b/actionpack/lib/action_controller/base.rb @@ -1233,8 +1233,10 @@ module ActionController #:nodoc: # Sets a HTTP 1.1 Cache-Control header of "no-cache" so no caching should occur by the browser or # intermediate caches (like caching proxy servers). + # By default, ActionController::Response sets Cache-Control to 'private, max-age=0, must-revalidate' if it encounters 'no-cache'. + # To avoid this, we set the Cache-Control to 'expires-now' here, which will be handled properly and set back to 'no-cache' afterwards. def expires_now #:doc: - response.headers["Cache-Control"] = "no-cache" + response.headers["Cache-Control"] = "expires-now" end # Resets the session by clearing out all the objects stored within and initializing a new session object. diff --git a/actionpack/lib/action_controller/response.rb b/actionpack/lib/action_controller/response.rb index ec1922c..5e0fcfa 100644 --- a/actionpack/lib/action_controller/response.rb +++ b/actionpack/lib/action_controller/response.rb @@ -206,7 +206,11 @@ module ActionController # :nodoc: end def set_conditional_cache_control! - if headers['Cache-Control'] == DEFAULT_HEADERS['Cache-Control'] + # Handle the case where we actually want the Cache-Control to be set to 'no-cache' + # which is when expire_now is called + if headers['Cache-Control'] == 'expires-now' + headers['Cache-Control'] = DEFAULT_HEADERS['Cache-Control'] + elsif headers['Cache-Control'] == DEFAULT_HEADERS['Cache-Control'] headers['Cache-Control'] = 'private, max-age=0, must-revalidate' end end -- 1.6.0.6