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