@@ -24,6 +24,7 @@ fn test_simple_miss() {
24
24
let policy = CachePolicy :: try_new (
25
25
& request_parts ( Request :: builder ( ) . method ( Method :: GET ) ) ,
26
26
& response_parts ( Response :: builder ( ) ) ,
27
+ now,
27
28
) . unwrap ( ) ;
28
29
29
30
assert ! ( policy. is_stale( now) ) ;
@@ -37,6 +38,7 @@ fn test_simple_hit() {
37
38
& response_parts (
38
39
Response :: builder ( ) . header ( header:: CACHE_CONTROL , "public, max-age=999999" ) ,
39
40
) ,
41
+ now,
40
42
) . unwrap ( ) ;
41
43
42
44
assert ! ( !policy. is_stale( now) ) ;
@@ -51,6 +53,7 @@ fn test_quoted_syntax() {
51
53
& response_parts (
52
54
Response :: builder ( ) . header ( header:: CACHE_CONTROL , " max-age = \" 678\" " ) ,
53
55
) ,
56
+ now,
54
57
) . unwrap ( ) ;
55
58
56
59
assert ! ( !policy. is_stale( now) ) ;
@@ -84,6 +87,7 @@ fn test_pre_check_tolerated() {
84
87
let not_storable = CachePolicy :: try_new (
85
88
& request_parts ( Request :: builder ( ) . method ( Method :: GET ) ) ,
86
89
& response_parts ( Response :: builder ( ) . header ( header:: CACHE_CONTROL , cache_control) ) ,
90
+ now,
87
91
) . unwrap_err ( ) ;
88
92
let policy = not_storable. 0 ;
89
93
@@ -152,6 +156,7 @@ fn test_age_can_make_stale() {
152
156
. header ( header:: CACHE_CONTROL , "max-age=100" )
153
157
. header ( header:: AGE , "101" ) ,
154
158
) ,
159
+ now,
155
160
) . unwrap ( ) ;
156
161
157
162
assert ! ( policy. is_stale( now) ) ;
@@ -168,6 +173,7 @@ fn test_age_not_always_stale() {
168
173
. header ( header:: CACHE_CONTROL , "max-age=20" )
169
174
. header ( header:: AGE , "15" ) ,
170
175
) ,
176
+ now,
171
177
) . unwrap ( ) ;
172
178
173
179
assert ! ( !policy. is_stale( now) ) ;
@@ -183,6 +189,7 @@ fn test_bogus_age_ignored() {
183
189
. header ( header:: CACHE_CONTROL , "max-age=20" )
184
190
. header ( header:: AGE , "golden" ) ,
185
191
) ,
192
+ now,
186
193
) . unwrap ( ) ;
187
194
188
195
assert ! ( !policy. is_stale( now) ) ;
@@ -198,6 +205,7 @@ fn test_cache_old_files() {
198
205
. header ( header:: DATE , now_rfc2822 ( ) )
199
206
. header ( header:: LAST_MODIFIED , "Mon, 07 Mar 2016 11:52:56 GMT" ) ,
200
207
) ,
208
+ now,
201
209
) . unwrap ( ) ;
202
210
203
211
assert ! ( !policy. is_stale( now) ) ;
@@ -212,6 +220,7 @@ fn test_immutable_simple_hit() {
212
220
& response_parts (
213
221
Response :: builder ( ) . header ( header:: CACHE_CONTROL , "immutable, max-age=999999" ) ,
214
222
) ,
223
+ now,
215
224
) . unwrap ( ) ;
216
225
217
226
assert ! ( !policy. is_stale( now) ) ;
@@ -224,6 +233,7 @@ fn test_immutable_can_expire() {
224
233
let policy = CachePolicy :: try_new (
225
234
& request_parts ( Request :: builder ( ) . method ( Method :: GET ) ) ,
226
235
& response_parts ( Response :: builder ( ) . header ( header:: CACHE_CONTROL , "immutable, max-age=0" ) ) ,
236
+ now,
227
237
) . unwrap ( ) ;
228
238
229
239
assert ! ( policy. is_stale( now) ) ;
@@ -241,6 +251,7 @@ fn test_cache_immutable_files() {
241
251
. header ( header:: CACHE_CONTROL , "immutable" )
242
252
. header ( header:: LAST_MODIFIED , now_rfc2822 ( ) ) ,
243
253
) ,
254
+ now,
244
255
) . unwrap ( ) ;
245
256
246
257
assert ! ( !policy. is_stale( now) ) ;
@@ -279,6 +290,7 @@ fn test_pragma_no_cache() {
279
290
. header ( header:: PRAGMA , "no-cache" )
280
291
. header ( header:: LAST_MODIFIED , "Mon, 07 Mar 2016 11:52:56 GMT" ) ,
281
292
) ,
293
+ now,
282
294
) . unwrap ( ) ;
283
295
284
296
assert ! ( policy. is_stale( now) ) ;
@@ -295,6 +307,7 @@ fn test_blank_cache_control_and_pragma_no_cache() {
295
307
. header ( header:: PRAGMA , "no-cache" )
296
308
. header ( header:: LAST_MODIFIED , "Mon, 07 Mar 2016 11:52:56 GMT" ) ,
297
309
) ,
310
+ now,
298
311
) . unwrap ( ) ;
299
312
300
313
assert ! ( !policy. is_stale( now) ) ;
@@ -308,6 +321,7 @@ fn test_no_store() {
308
321
& response_parts (
309
322
Response :: builder ( ) . header ( header:: CACHE_CONTROL , "no-store, public, max-age=1" ) ,
310
323
) ,
324
+ now,
311
325
) . unwrap_err ( ) ;
312
326
let policy = not_storable. 0 ;
313
327
@@ -324,7 +338,7 @@ fn test_observe_private_cache() {
324
338
let response =
325
339
response_parts ( Response :: builder ( ) . header ( header:: CACHE_CONTROL , private_header) ) ;
326
340
327
- let not_storable = CachePolicy :: try_new ( & request, & response) . unwrap_err ( ) ;
341
+ let not_storable = CachePolicy :: try_new ( & request, & response, now ) . unwrap_err ( ) ;
328
342
let shared_policy = not_storable. 0 ;
329
343
330
344
let unshared_policy = CachePolicy :: try_new_with_options (
@@ -353,7 +367,7 @@ fn test_do_not_share_cookies() {
353
367
. header ( header:: CACHE_CONTROL , "max-age=99" ) ,
354
368
) ;
355
369
356
- let shared_policy = CachePolicy :: try_new ( & request, & response) . unwrap ( ) ;
370
+ let shared_policy = CachePolicy :: try_new ( & request, & response, now ) . unwrap ( ) ;
357
371
358
372
let unshared_policy = CachePolicy :: try_new_with_options (
359
373
& request,
@@ -381,6 +395,7 @@ fn test_do_share_cookies_if_immutable() {
381
395
. header ( header:: SET_COOKIE , "foo=bar" )
382
396
. header ( header:: CACHE_CONTROL , "immutable, max-age=99" ) ,
383
397
) ,
398
+ now,
384
399
) . unwrap ( ) ;
385
400
386
401
assert ! ( !policy. is_stale( now) ) ;
@@ -397,6 +412,7 @@ fn test_cache_explicitly_public_cookie() {
397
412
. header ( header:: SET_COOKIE , "foo=bar" )
398
413
. header ( header:: CACHE_CONTROL , "max-age=5, public" ) ,
399
414
) ,
415
+ now,
400
416
) . unwrap ( ) ;
401
417
402
418
assert ! ( !policy. is_stale( now) ) ;
@@ -409,6 +425,7 @@ fn test_miss_max_age_equals_zero() {
409
425
let policy = CachePolicy :: try_new (
410
426
& request_parts ( Request :: builder ( ) . method ( Method :: GET ) ) ,
411
427
& response_parts ( Response :: builder ( ) . header ( header:: CACHE_CONTROL , "public, max-age=0" ) ) ,
428
+ now,
412
429
) . unwrap ( ) ;
413
430
414
431
assert ! ( policy. is_stale( now) ) ;
@@ -425,6 +442,7 @@ fn test_uncacheable_503() {
425
442
. status ( 503 )
426
443
. header ( header:: CACHE_CONTROL , "public, max-age=0" ) ,
427
444
) ,
445
+ now,
428
446
) . unwrap_err ( ) ;
429
447
let policy = not_storable. 0 ;
430
448
@@ -442,6 +460,7 @@ fn test_cacheable_301() {
442
460
. status ( 301 )
443
461
. header ( header:: LAST_MODIFIED , "Mon, 07 Mar 2016 11:52:56 GMT" ) ,
444
462
) ,
463
+ now,
445
464
) . unwrap ( ) ;
446
465
447
466
assert ! ( !policy. is_stale( now) ) ;
@@ -457,6 +476,7 @@ fn test_uncacheable_303() {
457
476
. status ( 303 )
458
477
. header ( header:: LAST_MODIFIED , "Mon, 07 Mar 2016 11:52:56 GMT" ) ,
459
478
) ,
479
+ now,
460
480
) . unwrap_err ( ) ;
461
481
let policy = not_storable. 0 ;
462
482
@@ -474,6 +494,7 @@ fn test_cacheable_303() {
474
494
. status ( 303 )
475
495
. header ( header:: CACHE_CONTROL , "max-age=1000" ) ,
476
496
) ,
497
+ now,
477
498
) . unwrap ( ) ;
478
499
479
500
assert ! ( !policy. is_stale( now) ) ;
@@ -489,6 +510,7 @@ fn test_uncacheable_412() {
489
510
. status ( 412 )
490
511
. header ( header:: CACHE_CONTROL , "public, max-age=1000" ) ,
491
512
) ,
513
+ now,
492
514
) . unwrap_err ( ) ;
493
515
let policy = not_storable. 0 ;
494
516
@@ -506,6 +528,7 @@ fn test_expired_expires_cache_with_max_age() {
506
528
. header ( header:: CACHE_CONTROL , "public, max-age=9999" )
507
529
. header ( header:: EXPIRES , "Sat, 07 May 2016 15:35:18 GMT" ) ,
508
530
) ,
531
+ now,
509
532
) . unwrap ( ) ;
510
533
511
534
assert ! ( !policy. is_stale( now) ) ;
@@ -522,6 +545,7 @@ fn request_mismatches() {
522
545
. header ( header:: CACHE_CONTROL , "public, max-age=9999" )
523
546
. header ( header:: EXPIRES , "Sat, 07 May 2016 15:35:18 GMT" ) ,
524
547
) ,
548
+ now,
525
549
) . unwrap ( ) ;
526
550
527
551
let mismatch = policy. before_request ( & request_parts ( Request :: builder ( ) . method ( Method :: POST ) . uri ( "/test" ) ) , now) ;
@@ -537,6 +561,7 @@ fn request_matches() {
537
561
Response :: builder ( )
538
562
. header ( header:: CACHE_CONTROL , "public, max-age=0" )
539
563
) ,
564
+ now,
540
565
) . unwrap ( ) ;
541
566
542
567
let mismatch = policy. before_request ( & request_parts ( Request :: builder ( ) . method ( Method :: GET ) . uri ( "/test" ) ) , now) ;
@@ -553,7 +578,7 @@ fn test_expired_expires_cached_with_s_maxage() {
553
578
. header ( header:: EXPIRES , "Sat, 07 May 2016 15:35:18 GMT" ) ,
554
579
) ;
555
580
556
- let shared_policy = CachePolicy :: try_new ( & request, & response) . unwrap ( ) ;
581
+ let shared_policy = CachePolicy :: try_new ( & request, & response, now ) . unwrap ( ) ;
557
582
558
583
let unshared_policy = CachePolicy :: try_new_with_options (
559
584
& request,
@@ -588,6 +613,7 @@ fn test_max_age_wins_over_future_expires() {
588
613
. unwrap ( ) ,
589
614
) ,
590
615
) ,
616
+ now,
591
617
) . unwrap ( ) ;
592
618
593
619
assert ! ( !policy. is_stale( now) ) ;
0 commit comments