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

Allow using combine the Cache-Control public and no-cache headers

Since #30367, if `no-cache` includes Cache-Control headers, special keys
like `public`, `must-revalidate` are ignored.
But in my understanding, `public` still need in case of want to cache
authenticated pages.
The authenticated pages to be cacheable, but still authenticated for
every user, need to specify the `Cache-Control: public, no-cache`.

For keys other than `public`, I did not know the case where it was
necessary to use it in combination with `no-cache`, so I fixed that can
be used only for `public`.

Ref: https://www.mnot.net/cache_docs/#CACHE-CONTROL

Fixes #34780.
This commit is contained in:
yuuji.yaginuma 2019-01-02 17:11:59 +09:00
parent 1e09019088
commit c1dd228579
2 changed files with 16 additions and 4 deletions

View file

@ -197,10 +197,12 @@ module ActionDispatch
if control.empty?
# Let middleware handle default behavior
elsif control[:no_cache]
self._cache_control = NO_CACHE
if control[:extras]
self._cache_control = _cache_control + ", #{control[:extras].join(', ')}"
end
options = []
options << PUBLIC if control[:public]
options << NO_CACHE
options.concat(control[:extras]) if control[:extras]
self._cache_control = options.join(", ")
else
extras = control[:extras]
max_age = control[:max_age]

View file

@ -183,6 +183,11 @@ class TestController < ActionController::Base
render action: "hello_world"
end
def conditional_hello_without_expires_and_public_header
response.headers["Cache-Control"] = "public, no-cache"
render action: "hello_world"
end
def conditional_hello_with_bangs
render action: "hello_world"
end
@ -418,6 +423,11 @@ class ExpiresInRenderTest < ActionController::TestCase
assert_equal "no-cache", @response.headers["Cache-Control"]
end
def test_no_expires_now_with_public
get :conditional_hello_without_expires_and_public_header
assert_equal "public, no-cache", @response.headers["Cache-Control"]
end
def test_date_header_when_expires_in
time = Time.mktime(2011, 10, 30)
Time.stub :now, time do