@@ -44,6 +44,7 @@ static DOC_RUST_LANG_ORG_REDIRECTS: Lazy<HashMap<&str, &str>> = Lazy::new(|| {
4444
4545fn generate_cache_directives_for (
4646 max_age : Option < u32 > ,
47+ s_max_age : Option < u32 > ,
4748 stale_while_revalidate : Option < u32 > ,
4849) -> Option < CacheControl > {
4950 let mut directives = vec ! [ ] ;
@@ -59,6 +60,10 @@ fn generate_cache_directives_for(
5960 directives. push ( CacheDirective :: MaxAge ( seconds) ) ;
6061 }
6162
63+ if let Some ( seconds) = s_max_age {
64+ directives. push ( CacheDirective :: SMaxAge ( seconds) ) ;
65+ }
66+
6267 if !directives. is_empty ( ) {
6368 Some ( CacheControl ( directives) )
6469 } else {
@@ -288,11 +293,13 @@ impl RustdocPage {
288293 let cache_control = if is_latest_url {
289294 generate_cache_directives_for (
290295 Some ( config. cache_control_max_age_latest . unwrap_or ( 0 ) ) ,
296+ config. cache_control_s_max_age_latest ,
291297 config. cache_control_stale_while_revalidate_latest ,
292298 )
293299 } else {
294300 generate_cache_directives_for (
295301 config. cache_control_max_age ,
302+ config. cache_control_s_max_age ,
296303 config. cache_control_stale_while_revalidate ,
297304 )
298305 } ;
@@ -976,7 +983,9 @@ mod test {
976983 wrapper ( |env| {
977984 env. override_config ( |config| {
978985 config. cache_control_max_age = Some ( 666 ) ;
986+ config. cache_control_s_max_age = Some ( 777 ) ;
979987 config. cache_control_max_age_latest = Some ( 999 ) ;
988+ config. cache_control_s_max_age_latest = Some ( 888 ) ;
980989 config. cache_control_stale_while_revalidate = Some ( 2222222 ) ;
981990 config. cache_control_stale_while_revalidate_latest = Some ( 3333333 ) ;
982991 } ) ;
@@ -994,15 +1003,15 @@ mod test {
9941003 let resp = web. get ( "/dummy/latest/dummy/" ) . send ( ) ?;
9951004 assert_eq ! (
9961005 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 "
9981007 ) ;
9991008 }
10001009
10011010 {
10021011 let resp = web. get ( "/dummy/0.1.0/dummy/" ) . send ( ) ?;
10031012 assert_eq ! (
10041013 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 "
10061015 ) ;
10071016 }
10081017 Ok ( ( ) )
0 commit comments