@@ -39,6 +39,7 @@ static DOC_RUST_LANG_ORG_REDIRECTS: Lazy<HashMap<&str, &str>> = Lazy::new(|| {
39
39
40
40
fn generate_cache_directives_for (
41
41
max_age : Option < u32 > ,
42
+ s_max_age : Option < u32 > ,
42
43
stale_while_revalidate : Option < u32 > ,
43
44
) -> Option < CacheControl > {
44
45
let mut directives = vec ! [ ] ;
@@ -54,6 +55,10 @@ fn generate_cache_directives_for(
54
55
directives. push ( CacheDirective :: MaxAge ( seconds) ) ;
55
56
}
56
57
58
+ if let Some ( seconds) = s_max_age {
59
+ directives. push ( CacheDirective :: SMaxAge ( seconds) ) ;
60
+ }
61
+
57
62
if !directives. is_empty ( ) {
58
63
Some ( CacheControl ( directives) )
59
64
} else {
@@ -285,11 +290,13 @@ impl RustdocPage {
285
290
let cache_control = if is_latest_url {
286
291
generate_cache_directives_for (
287
292
Some ( config. cache_control_max_age_latest . unwrap_or ( 0 ) ) ,
293
+ config. cache_control_s_max_age_latest ,
288
294
config. cache_control_stale_while_revalidate_latest ,
289
295
)
290
296
} else {
291
297
generate_cache_directives_for (
292
298
config. cache_control_max_age ,
299
+ config. cache_control_s_max_age ,
293
300
config. cache_control_stale_while_revalidate ,
294
301
)
295
302
} ;
@@ -973,7 +980,9 @@ mod test {
973
980
wrapper ( |env| {
974
981
env. override_config ( |config| {
975
982
config. cache_control_max_age = Some ( 666 ) ;
983
+ config. cache_control_s_max_age = Some ( 777 ) ;
976
984
config. cache_control_max_age_latest = Some ( 999 ) ;
985
+ config. cache_control_s_max_age_latest = Some ( 888 ) ;
977
986
config. cache_control_stale_while_revalidate = Some ( 2222222 ) ;
978
987
config. cache_control_stale_while_revalidate_latest = Some ( 3333333 ) ;
979
988
} ) ;
@@ -991,15 +1000,15 @@ mod test {
991
1000
let resp = web. get ( "/dummy/latest/dummy/" ) . send ( ) ?;
992
1001
assert_eq ! (
993
1002
resp. headers( ) . get( "Cache-Control" ) . unwrap( ) ,
994
- & "stale-while-revalidate=3333333, max-age=999"
1003
+ & "stale-while-revalidate=3333333, max-age=999, s-maxage=888 "
995
1004
) ;
996
1005
}
997
1006
998
1007
{
999
1008
let resp = web. get ( "/dummy/0.1.0/dummy/" ) . send ( ) ?;
1000
1009
assert_eq ! (
1001
1010
resp. headers( ) . get( "Cache-Control" ) . unwrap( ) ,
1002
- & "stale-while-revalidate=2222222, max-age=666"
1011
+ & "stale-while-revalidate=2222222, max-age=666, s-maxage=777 "
1003
1012
) ;
1004
1013
}
1005
1014
Ok ( ( ) )
0 commit comments