1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

let expires_in accept a must_revalidate flag

This commit is contained in:
Xavier Noria 2012-02-17 05:16:58 -08:00
parent 4bb6ed7744
commit ce51edb73b
3 changed files with 29 additions and 2 deletions

View file

@ -1,5 +1,8 @@
## Rails 4.0.0 (unreleased) ##
* `expires_in` accepts a `must_revalidate` flag. If true, "must-revalidate"
is added to the Cache-Control header. *fxn*
* Add `date_field` and `date_field_tag` helpers which render an `input[type="date"]` tag *Olek Janiszewski*
* Adds `image_url`, `javascript_url`, `stylesheet_url`, `audio_url`, `video_url`, and `font_url`

View file

@ -110,13 +110,17 @@ module ActionController
#
# Examples:
# expires_in 20.minutes
# expires_in 3.hours, :public => true
# expires_in 3.hours, :public => true, :must_revalidate => true
# expires_in 3.hours, 'max-stale' => 5.hours, :public => true
#
# This method will overwrite an existing Cache-Control header.
# See http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html for more possibilities.
def expires_in(seconds, options = {}) #:doc:
response.cache_control.merge!(:max_age => seconds, :public => options.delete(:public))
response.cache_control.merge!(
:max_age => seconds,
:public => options.delete(:public),
:must_revalidate => options.delete(:must_revalidate)
)
options.delete(:private)
response.cache_control[:extras] = options.map {|k,v| "#{k}=#{v}"}

View file

@ -91,6 +91,16 @@ class TestController < ActionController::Base
render :action => 'hello_world'
end
def conditional_hello_with_expires_in_with_must_revalidate
expires_in 1.minute, :must_revalidate => true
render :action => 'hello_world'
end
def conditional_hello_with_expires_in_with_public_and_must_revalidate
expires_in 1.minute, :public => true, :must_revalidate => true
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
render :action => 'hello_world'
@ -1399,6 +1409,16 @@ class ExpiresInRenderTest < ActionController::TestCase
assert_equal "max-age=60, public", @response.headers["Cache-Control"]
end
def test_expires_in_header_with_must_revalidate
get :conditional_hello_with_expires_in_with_must_revalidate
assert_equal "max-age=60, private, must-revalidate", @response.headers["Cache-Control"]
end
def test_expires_in_header_with_public_and_must_revalidate
get :conditional_hello_with_expires_in_with_public_and_must_revalidate
assert_equal "max-age=60, public, must-revalidate", @response.headers["Cache-Control"]
end
def test_expires_in_header_with_additional_headers
get :conditional_hello_with_expires_in_with_public_with_more_keys
assert_equal "max-age=60, public, max-stale=18000", @response.headers["Cache-Control"]