File tree Expand file tree Collapse file tree 4 files changed +36
-8
lines changed Expand file tree Collapse file tree 4 files changed +36
-8
lines changed Original file line number Diff line number Diff line change
1
+ * Add support for 'private, no-store' Cache-Control headers.
2
+
3
+ Previously, 'no-store' was exclusive; no other directives could be specified.
4
+
5
+ * Alex Smith*
6
+
1
7
* Expand payload of ` unpermitted_parameters.action_controller ` instrumentation to allow subscribers to
2
8
know which controller action received unpermitted parameters.
3
9
Original file line number Diff line number Diff line change @@ -195,31 +195,30 @@ def merge_and_normalize_cache_control!(cache_control)
195
195
196
196
control . merge! cache_control
197
197
198
+ options = [ ]
199
+
198
200
if control [ :no_store ]
199
- self . _cache_control = NO_STORE
201
+ options << PRIVATE if control [ :private ]
202
+ options << NO_STORE
200
203
elsif control [ :no_cache ]
201
- options = [ ]
202
204
options << PUBLIC if control [ :public ]
203
205
options << NO_CACHE
204
206
options . concat ( control [ :extras ] ) if control [ :extras ]
205
-
206
- self . _cache_control = options . join ( ", " )
207
207
else
208
208
extras = control [ :extras ]
209
209
max_age = control [ :max_age ]
210
210
stale_while_revalidate = control [ :stale_while_revalidate ]
211
211
stale_if_error = control [ :stale_if_error ]
212
212
213
- options = [ ]
214
213
options << "max-age=#{ max_age . to_i } " if max_age
215
214
options << ( control [ :public ] ? PUBLIC : PRIVATE )
216
215
options << MUST_REVALIDATE if control [ :must_revalidate ]
217
216
options << "stale-while-revalidate=#{ stale_while_revalidate . to_i } " if stale_while_revalidate
218
217
options << "stale-if-error=#{ stale_if_error . to_i } " if stale_if_error
219
218
options . concat ( extras ) if extras
220
-
221
- self . _cache_control = options . join ( ", " )
222
219
end
220
+
221
+ self . _cache_control = options . join ( ", " )
223
222
end
224
223
end
225
224
end
Original file line number Diff line number Diff line change @@ -62,12 +62,24 @@ def test_cache_control_is_set_manually
62
62
assert_equal "public" , @response . headers [ "Cache-Control" ]
63
63
end
64
64
65
+ def test_cache_control_no_store_default_standalone
66
+ @response . set_header ( "Cache-Control" , "no-store" )
67
+ @response . stream . write "omg"
68
+ assert_equal "no-store" , @response . headers [ "Cache-Control" ]
69
+ end
70
+
65
71
def test_cache_control_no_store_is_respected
66
- @response . set_header ( "Cache-Control" , "private , no-store" )
72
+ @response . set_header ( "Cache-Control" , "public , no-store" )
67
73
@response . stream . write "omg"
68
74
assert_equal "no-store" , @response . headers [ "Cache-Control" ]
69
75
end
70
76
77
+ def test_cache_control_no_store_private
78
+ @response . set_header ( "Cache-Control" , "private, no-store" )
79
+ @response . stream . write "omg"
80
+ assert_equal "private, no-store" , @response . headers [ "Cache-Control" ]
81
+ end
82
+
71
83
def test_content_length_is_removed
72
84
@response . headers [ "Content-Length" ] = "1234"
73
85
@response . stream . write "omg"
Original file line number Diff line number Diff line change @@ -306,6 +306,17 @@ def test_only_set_charset_still_defaults_to_text_html
306
306
assert_equal ( "no-store" , resp . headers [ "Cache-Control" ] )
307
307
end
308
308
309
+ test "respect private, no-store cache-control" do
310
+ resp = ActionDispatch ::Response . new . tap { |response |
311
+ response . cache_control [ :private ] = true
312
+ response . cache_control [ :no_store ] = true
313
+ response . body = "Hello"
314
+ }
315
+ resp . to_a
316
+
317
+ assert_equal ( "private, no-store" , resp . headers [ "Cache-Control" ] )
318
+ end
319
+
309
320
test "read content type with default charset utf-8" do
310
321
resp = ActionDispatch ::Response . new ( 200 , "Content-Type" => "text/xml" )
311
322
assert_equal ( "utf-8" , resp . charset )
You can’t perform that action at this time.
0 commit comments