MCPcopy Create free account
hub / github.com/nodejs/node / stripNecessaryHeaders

Function stripNecessaryHeaders

deps/undici/src/lib/handler/cache-handler.js:534–576  ·  view source on GitHub ↗

* Strips headers required to be removed in cached responses * @param {import('../../types/header.d.ts').IncomingHttpHeaders} resHeaders * @param {import('../../types/cache-interceptor.d.ts').default.CacheControlDirectives} cacheControlDirectives * @returns {Record }

(resHeaders, cacheControlDirectives)

Source from the content-addressed store, hash-verified

532 * @returns {Record<string, string | string []>}
533 */
534function stripNecessaryHeaders (resHeaders, cacheControlDirectives) {
535 const headersToRemove = [
536 'connection',
537 'proxy-authenticate',
538 'proxy-authentication-info',
539 'proxy-authorization',
540 'proxy-connection',
541 'te',
542 'transfer-encoding',
543 'upgrade',
544 // We'll add age back when serving it
545 'age'
546 ]
547
548 if (resHeaders['connection']) {
549 if (Array.isArray(resHeaders['connection'])) {
550 // connection: a
551 // connection: b
552 headersToRemove.push(...resHeaders['connection'].map(header => header.trim()))
553 } else {
554 // connection: a, b
555 headersToRemove.push(...resHeaders['connection'].split(',').map(header => header.trim()))
556 }
557 }
558
559 if (Array.isArray(cacheControlDirectives['no-cache'])) {
560 headersToRemove.push(...cacheControlDirectives['no-cache'])
561 }
562
563 if (Array.isArray(cacheControlDirectives['private'])) {
564 headersToRemove.push(...cacheControlDirectives['private'])
565 }
566
567 let strippedHeaders
568 for (const headerName of headersToRemove) {
569 if (resHeaders[headerName]) {
570 strippedHeaders ??= { ...resHeaders }
571 delete strippedHeaders[headerName]
572 }
573 }
574
575 return strippedHeaders ?? resHeaders
576}
577
578/**
579 * @param {Date} date

Callers 1

onResponseStartMethod · 0.85

Calls 3

mapMethod · 0.65
pushMethod · 0.45
splitMethod · 0.45

Tested by

no test coverage detected