MCPcopy Create free account
hub / github.com/nodejs/undici / getAge

Function getAge

lib/handler/cache-handler.js:579–599  ·  view source on GitHub ↗

* @param {string | string[]} ageHeader * @returns {number | undefined}

(ageHeader)

Source from the content-addressed store, hash-verified

577 * @returns {number | undefined}
578 */
579function getAge (ageHeader) {
580 let ageValue = ageHeader
581 if (Array.isArray(ageValue)) {
582 if (ageValue.length !== 1) {
583 return MAX_RESPONSE_AGE
584 }
585
586 ageValue = ageValue[0]
587 }
588
589 if (typeof ageValue !== 'string' || !/^[\t ]*[0-9]+[\t ]*$/.test(ageValue)) {
590 return MAX_RESPONSE_AGE
591 }
592
593 const age = BigInt(ageValue.replace(/^[\t ]+|[\t ]+$/g, ''))
594 if (age >= BigInt(MAX_RESPONSE_AGE / 1000)) {
595 return MAX_RESPONSE_AGE
596 }
597
598 return Number(age) * 1000
599}
600
601/**
602 * @param {import('../../types/cache-interceptor.d.ts').default.CacheOptions['type']} cacheType

Callers 1

onResponseStartMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected