diff --git a/actionpack/lib/action_controller/base/conditional_get.rb b/actionpack/lib/action_controller/base/conditional_get.rb index d287ec4..4804913 100644 --- a/actionpack/lib/action_controller/base/conditional_get.rb +++ b/actionpack/lib/action_controller/base/conditional_get.rb @@ -102,7 +102,11 @@ module ActionController # Examples: # expires_in 20.minutes # expires_in 3.hours, :public => true + # expires_in 3.hours, :private => false # this will issue public instruction # expires in 3.hours, 'max-stale' => 5.hours, :public => true + # + # Note: do not to specify contradictory public/private pairs, e.g.: + # expires_in 1.hour, :public => false, :private => false # # This method will overwrite an existing Cache-Control header. # See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html for more possibilities. @@ -111,7 +115,12 @@ module ActionController cache_control << "max-age=#{seconds}" cache_control.delete("no-cache") - if options[:public] + # To support initial 2.x API of allowing ":private => false" as per #2940 + # the logic _should_ be to check for options[:private] == false + # rather than using the implicit, which would cause incorrect behavior: + # !options[:private] + # if-evaluation + if options[:public] || (options[:private] == false) cache_control.delete("private") cache_control << "public" else diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index acb0c89..2c5c1e7 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -61,6 +61,11 @@ class TestController < ActionController::Base expires_in 1.minute, :public => true render :action => 'hello_world' end + + def conditional_hello_with_expires_in_with_private_false + expires_in 1.minute, :private => false + render :action => 'hello_world' + end def conditional_hello_with_expires_in_with_public_with_more_keys expires_in 1.minute, :public => true, 'max-stale' => 5.hours @@ -1301,6 +1306,11 @@ class ExpiresInRenderTest < ActionController::TestCase get :conditional_hello_with_expires_in_with_public assert_equal "max-age=60, public", @response.headers["Cache-Control"] end + + def test_expires_in_head_with_private_false + get :conditional_hello_with_expires_in_with_private_false + assert_equal "max-age=60, public", @response.headers["Cache-Control"] + end def test_expires_in_header_with_additional_headers get :conditional_hello_with_expires_in_with_public_with_more_keys