@@ -235,13 +235,13 @@ impl RustdocPage {
235235 let is_latest_url = self . is_latest_url ;
236236 // Build the page of documentation
237237 let ctx = ctry ! ( req, tera:: Context :: from_serialize( self ) ) ;
238+ let config = extension ! ( req, Config ) ;
238239 // Extract the head and body of the rustdoc file so that we can insert it into our own html
239240 // while logging OOM errors from html rewriting
240241 let html = match utils:: rewrite_lol ( rustdoc_html, max_parse_memory, ctx, templates) {
241242 Err ( RewritingError :: MemoryLimitExceeded ( ..) ) => {
242243 metrics. html_rewrite_ooms . inc ( ) ;
243244
244- let config = extension ! ( req, Config ) ;
245245 let err = anyhow ! (
246246 "Failed to serve the rustdoc file '{}' because rewriting it surpassed the memory limit of {} bytes" ,
247247 file_path, config. max_parse_memory,
@@ -259,13 +259,21 @@ impl RustdocPage {
259259 . headers
260260 . set ( CacheControl ( vec ! [ CacheDirective :: MaxAge ( 0 ) ] ) ) ;
261261 } else {
262- response. headers . set ( CacheControl ( vec ! [
263- CacheDirective :: Extension (
262+ let mut directives = vec ! [ ] ;
263+ if let Some ( seconds) = config. cache_control_stale_while_revalidate {
264+ directives. push ( CacheDirective :: Extension (
264265 "stale-while-revalidate" . to_string ( ) ,
265- Some ( "2592000" . to_string( ) ) , // sixty days
266- ) ,
267- CacheDirective :: MaxAge ( 600u32 ) , // ten minutes
268- ] ) ) ;
266+ Some ( format ! ( "{}" , seconds) ) ,
267+ ) ) ;
268+ }
269+
270+ if let Some ( seconds) = config. cache_control_max_age {
271+ directives. push ( CacheDirective :: MaxAge ( seconds) ) ;
272+ }
273+
274+ if directives. len ( ) > 0 {
275+ response. headers . set ( CacheControl ( directives) ) ;
276+ }
269277 }
270278 Ok ( response)
271279 }
0 commit comments