@@ -571,38 +571,34 @@ function wrapper(context) {
571571 }
572572
573573 if ( ! getResponseHeader ( res , "Cache-Control" ) ) {
574- // TODO enable the `cacheImmutable` by default for the next major release
575- const cacheControl =
576- context . options . cacheImmutable && extra . immutable
577- ? { immutable : true }
578- : context . options . cacheControl ;
579-
580- if ( cacheControl ) {
581- let cacheControlValue ;
582-
583- if ( typeof cacheControl === "boolean" ) {
584- cacheControlValue = "public, max-age=31536000" ;
585- } else if ( typeof cacheControl === "number" ) {
586- const maxAge = Math . floor (
587- Math . min ( Math . max ( 0 , cacheControl ) , MAX_MAX_AGE ) / 1000 ,
588- ) ;
574+ const hasCacheImmutable =
575+ context . options . cacheImmutable === undefined
576+ ? true
577+ : context . options . cacheImmutable ;
578+
579+ let { cacheControl } = context . options ;
580+
581+ // Normalize cacheControl to object
582+ if ( typeof cacheControl === "string" ) {
583+ setResponseHeader ( res , "Cache-Control" , cacheControl ) ;
584+ } else if ( hasCacheImmutable && extra . immutable ) {
585+ cacheControl = { immutable : true } ;
586+ } else if ( typeof cacheControl === "boolean" ) {
587+ cacheControl = { maxAge : MAX_MAX_AGE } ;
588+ } else if ( typeof cacheControl === "number" ) {
589+ cacheControl = { maxAge : cacheControl } ;
590+ }
589591
590- cacheControlValue = `public, max-age=${ maxAge } ` ;
591- } else if ( typeof cacheControl === "string" ) {
592- cacheControlValue = cacheControl ;
593- } else {
594- const maxAge = cacheControl . maxAge
595- ? Math . floor (
596- Math . min ( Math . max ( 0 , cacheControl . maxAge ) , MAX_MAX_AGE ) /
597- 1000 ,
598- )
599- : MAX_MAX_AGE / 1000 ;
600-
601- cacheControlValue = `public, max-age=${ maxAge } ` ;
602-
603- if ( cacheControl . immutable ) {
604- cacheControlValue += ", immutable" ;
605- }
592+ if ( cacheControl && typeof cacheControl === "object" ) {
593+ const maxAge =
594+ cacheControl . maxAge !== undefined
595+ ? Math . min ( Math . max ( 0 , cacheControl . maxAge ) , MAX_MAX_AGE )
596+ : MAX_MAX_AGE ;
597+
598+ let cacheControlValue = `public, max-age=${ Math . floor ( maxAge / 1000 ) } ` ;
599+
600+ if ( cacheControl . immutable && hasCacheImmutable ) {
601+ cacheControlValue += ", immutable" ;
606602 }
607603
608604 setResponseHeader ( res , "Cache-Control" , cacheControlValue ) ;
0 commit comments