88} from 'date-fns' ;
99
1010import { HttpExchange , ExchangeMessage } from '../../types' ;
11- import { lastHeader , asHeaderArray } from '../../util/headers' ;
11+ import { getHeaderValue , asHeaderArray } from '../../util/headers' ;
1212import { joinAnd } from '../../util/text' ;
1313import { escapeForMarkdownEmbedding } from '../ui/markdown' ;
1414
@@ -106,7 +106,7 @@ export function explainCacheability(exchange: HttpExchange): (
106106 // This is a CORS preflight request - it's not really cacheable, but the CORS
107107 // headers specifically (probably the only interesting bit) are, via their
108108 // own separate funky mechanism.
109- const maxAgeHeader = lastHeader ( response . headers [ 'access-control-max-age' ] ) ;
109+ const maxAgeHeader = getHeaderValue ( response . headers , 'access-control-max-age' ) ;
110110 const maxAge = maxAgeHeader ? parseInt ( maxAgeHeader , 10 ) : undefined ;
111111
112112 if ( maxAge !== undefined && maxAge >= 1 ) {
@@ -238,7 +238,7 @@ export function explainCacheability(exchange: HttpExchange): (
238238 ` ;
239239
240240 const contentLocationUrl = response . headers [ 'content-location' ] ?
241- new URL ( lastHeader ( response . headers [ 'content-location' ] ! ) , request . url ) : undefined ;
241+ new URL ( getHeaderValue ( response . headers , 'content-location' ) ! , request . url ) : undefined ;
242242
243243 const hasFreshnessInfo =
244244 ! ! responseCCDirectives [ 'max-age' ] ||
@@ -272,7 +272,7 @@ export function explainCacheability(exchange: HttpExchange): (
272272 let warning : string | undefined ;
273273
274274 const responseDateHeader = response . headers [ 'date' ] ?
275- parseDate ( lastHeader ( response . headers [ 'date' ] ) ! )
275+ parseDate ( getHeaderValue ( response . headers , 'date' ) ! )
276276 : undefined ;
277277
278278 if ( ! responseDateHeader ) {
@@ -287,7 +287,7 @@ export function explainCacheability(exchange: HttpExchange): (
287287 predictably.
288288 ` ;
289289 } else if ( response . headers [ 'expires' ] && Math . abs ( differenceInSeconds (
290- parseDate ( lastHeader ( response . headers [ 'expires' ] ! ) ) ,
290+ parseDate ( getHeaderValue ( response . headers , 'expires' ) ! ) ,
291291 addSeconds ( responseDateHeader , responseCCDirectives [ 'max-age' ] )
292292 ) ) > 60 ) {
293293 warning = dedent `
@@ -318,7 +318,7 @@ export function explainCacheability(exchange: HttpExchange): (
318318 } ;
319319 }
320320
321- if ( lastHeader ( response . headers [ 'expires' ] ) !== undefined ) {
321+ if ( getHeaderValue ( response . headers , 'expires' ) !== undefined ) {
322322 // Expires set, but not max-age (checked above).
323323 return {
324324 cacheable : true ,
@@ -649,7 +649,7 @@ export function explainCacheLifetime(exchange: HttpExchange): Explanation | unde
649649 const responseCCDirectives = parseCCDirectives ( response ) ;
650650
651651 if ( request . method === 'OPTIONS' ) {
652- const maxAgeHeader = lastHeader ( response . headers [ 'access-control-max-age' ] ) ;
652+ const maxAgeHeader = getHeaderValue ( response . headers , 'access-control-max-age' ) ;
653653
654654 if ( maxAgeHeader ) {
655655 const maxAge = parseInt ( maxAgeHeader ! , 10 ) ;
@@ -694,8 +694,8 @@ export function explainCacheLifetime(exchange: HttpExchange): Explanation | unde
694694 } ;
695695 }
696696
697- const dateHeader = lastHeader ( response . headers [ 'date' ] ) ;
698- const expiresHeader = lastHeader ( response . headers [ 'expires' ] ) ;
697+ const dateHeader = getHeaderValue ( response . headers , 'date' ) ;
698+ const expiresHeader = getHeaderValue ( response . headers , 'expires' ) ;
699699 const maxAge = responseCCDirectives [ 'max-age' ] ;
700700 const sharedMaxAge = responseCCDirectives [ 's-maxage' ] !== undefined ?
701701 responseCCDirectives [ 's-maxage' ] : maxAge ;
0 commit comments