Skip to content

Commit 999df68

Browse files
authored
Merge pull request rails#52197 from heka1024/cache-controler-immutable
Support `immutable` directive in Cache-Control
2 parents 5103ba8 + d98cfde commit 999df68

File tree

4 files changed

+22
-0
lines changed

4 files changed

+22
-0
lines changed

actionpack/CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
* Support `immutable` directive in Cache-Control
2+
3+
```ruby
4+
expires_in 1.minute, public: true, immutable: true
5+
# Cache-Control: public, max-age=60, immutable
6+
```
7+
8+
*heka1024*
9+
110
* Add `:wasm_unsafe_eval` mapping for `content_security_policy`
211

312
```ruby

actionpack/lib/action_controller/metal/conditional_get.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ def expires_in(seconds, options = {})
293293
must_revalidate: options.delete(:must_revalidate),
294294
stale_while_revalidate: options.delete(:stale_while_revalidate),
295295
stale_if_error: options.delete(:stale_if_error),
296+
immutable: options.delete(:immutable),
296297
)
297298
options.delete(:private)
298299

actionpack/lib/action_dispatch/http/cache.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ def prepare_cache_control!
171171
PUBLIC = "public"
172172
PRIVATE = "private"
173173
MUST_REVALIDATE = "must-revalidate"
174+
IMMUTABLE = "immutable"
174175

175176
def handle_conditional_get!
176177
# Normally default cache control setting is handled by ETag middleware. But, if
@@ -221,6 +222,7 @@ def merge_and_normalize_cache_control!(cache_control)
221222
options << MUST_REVALIDATE if control[:must_revalidate]
222223
options << "stale-while-revalidate=#{stale_while_revalidate.to_i}" if stale_while_revalidate
223224
options << "stale-if-error=#{stale_if_error.to_i}" if stale_if_error
225+
options << IMMUTABLE if control[:immutable]
224226
options.concat(extras) if extras
225227
end
226228

actionpack/test/controller/render_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,11 @@ def conditional_hello_with_expires_in_with_stale_if_error
179179
render action: "hello_world"
180180
end
181181

182+
def conditional_hello_with_expires_in_with_immutable
183+
expires_in 1.minute, public: true, immutable: true
184+
render action: "hello_world"
185+
end
186+
182187
def conditional_hello_with_expires_in_with_public_with_more_keys
183188
expires_in 1.minute, :public => true, "s-maxage" => 5.hours
184189
render action: "hello_world"
@@ -442,6 +447,11 @@ def test_expires_in_header_with_stale_if_error
442447
assert_equal "max-age=60, public, stale-if-error=300", @response.headers["Cache-Control"]
443448
end
444449

450+
def test_expires_in_header_with_immutable
451+
get :conditional_hello_with_expires_in_with_immutable
452+
assert_equal "max-age=60, public, immutable", @response.headers["Cache-Control"]
453+
end
454+
445455
def test_expires_in_header_with_additional_headers
446456
get :conditional_hello_with_expires_in_with_public_with_more_keys
447457
assert_equal "max-age=60, public, s-maxage=18000", @response.headers["Cache-Control"]

0 commit comments

Comments
 (0)