@@ -235,13 +235,13 @@ impl RustdocPage {
235
235
let is_latest_url = self . is_latest_url ;
236
236
// Build the page of documentation
237
237
let ctx = ctry ! ( req, tera:: Context :: from_serialize( self ) ) ;
238
+ let config = extension ! ( req, Config ) ;
238
239
// Extract the head and body of the rustdoc file so that we can insert it into our own html
239
240
// while logging OOM errors from html rewriting
240
241
let html = match utils:: rewrite_lol ( rustdoc_html, max_parse_memory, ctx, templates) {
241
242
Err ( RewritingError :: MemoryLimitExceeded ( ..) ) => {
242
243
metrics. html_rewrite_ooms . inc ( ) ;
243
244
244
- let config = extension ! ( req, Config ) ;
245
245
let err = anyhow ! (
246
246
"Failed to serve the rustdoc file '{}' because rewriting it surpassed the memory limit of {} bytes" ,
247
247
file_path, config. max_parse_memory,
@@ -259,13 +259,21 @@ impl RustdocPage {
259
259
. headers
260
260
. set ( CacheControl ( vec ! [ CacheDirective :: MaxAge ( 0 ) ] ) ) ;
261
261
} 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 (
264
265
"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. empty ( ) {
275
+ response. headers . set ( CacheControl ( directives) ) ;
276
+ }
269
277
}
270
278
Ok ( response)
271
279
}
0 commit comments