Merge pull request #52197 from heka1024/cache-controler-immutable
Support `immutable` directive in Cache-Control
This commit is contained in:
commit
999df686de
@ -1,3 +1,12 @@
|
||||
* Support `immutable` directive in Cache-Control
|
||||
|
||||
```ruby
|
||||
expires_in 1.minute, public: true, immutable: true
|
||||
# Cache-Control: public, max-age=60, immutable
|
||||
```
|
||||
|
||||
*heka1024*
|
||||
|
||||
* Add `:wasm_unsafe_eval` mapping for `content_security_policy`
|
||||
|
||||
```ruby
|
||||
|
@ -293,6 +293,7 @@ def expires_in(seconds, options = {})
|
||||
must_revalidate: options.delete(:must_revalidate),
|
||||
stale_while_revalidate: options.delete(:stale_while_revalidate),
|
||||
stale_if_error: options.delete(:stale_if_error),
|
||||
immutable: options.delete(:immutable),
|
||||
)
|
||||
options.delete(:private)
|
||||
|
||||
|
@ -171,6 +171,7 @@ def prepare_cache_control!
|
||||
PUBLIC = "public"
|
||||
PRIVATE = "private"
|
||||
MUST_REVALIDATE = "must-revalidate"
|
||||
IMMUTABLE = "immutable"
|
||||
|
||||
def handle_conditional_get!
|
||||
# Normally default cache control setting is handled by ETag middleware. But, if
|
||||
@ -221,6 +222,7 @@ def merge_and_normalize_cache_control!(cache_control)
|
||||
options << MUST_REVALIDATE if control[:must_revalidate]
|
||||
options << "stale-while-revalidate=#{stale_while_revalidate.to_i}" if stale_while_revalidate
|
||||
options << "stale-if-error=#{stale_if_error.to_i}" if stale_if_error
|
||||
options << IMMUTABLE if control[:immutable]
|
||||
options.concat(extras) if extras
|
||||
end
|
||||
|
||||
|
@ -179,6 +179,11 @@ def conditional_hello_with_expires_in_with_stale_if_error
|
||||
render action: "hello_world"
|
||||
end
|
||||
|
||||
def conditional_hello_with_expires_in_with_immutable
|
||||
expires_in 1.minute, public: true, immutable: true
|
||||
render action: "hello_world"
|
||||
end
|
||||
|
||||
def conditional_hello_with_expires_in_with_public_with_more_keys
|
||||
expires_in 1.minute, :public => true, "s-maxage" => 5.hours
|
||||
render action: "hello_world"
|
||||
@ -442,6 +447,11 @@ def test_expires_in_header_with_stale_if_error
|
||||
assert_equal "max-age=60, public, stale-if-error=300", @response.headers["Cache-Control"]
|
||||
end
|
||||
|
||||
def test_expires_in_header_with_immutable
|
||||
get :conditional_hello_with_expires_in_with_immutable
|
||||
assert_equal "max-age=60, public, immutable", @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, s-maxage=18000", @response.headers["Cache-Control"]
|
||||
|
Loading…
Reference in New Issue
Block a user