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:
parent
4bb6ed7744
commit
ce51edb73b
3 changed files with 29 additions and 2 deletions
|
@ -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`
|
||||
|
|
|
@ -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}"}
|
||||
|
|
|
@ -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"]
|
||||
|
|
Loading…
Reference in a new issue