diff options
Diffstat (limited to 'deps/npm/node_modules/make-fetch-happen/lib/cache/entry.js')
-rw-r--r-- | deps/npm/node_modules/make-fetch-happen/lib/cache/entry.js | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/deps/npm/node_modules/make-fetch-happen/lib/cache/entry.js b/deps/npm/node_modules/make-fetch-happen/lib/cache/entry.js index dba89d715d..4514109507 100644 --- a/deps/npm/node_modules/make-fetch-happen/lib/cache/entry.js +++ b/deps/npm/node_modules/make-fetch-happen/lib/cache/entry.js @@ -1,5 +1,5 @@ const { Request, Response } = require('minipass-fetch') -const Minipass = require('minipass') +const { Minipass } = require('minipass') const MinipassFlush = require('minipass-flush') const cacache = require('cacache') const url = require('url') @@ -99,6 +99,12 @@ const getMetadata = (request, response, options) => { } } + for (const name of options.cacheAdditionalHeaders) { + if (response.headers.has(name)) { + metadata.resHeaders[name] = response.headers.get(name) + } + } + return metadata } @@ -331,6 +337,7 @@ class CacheEntry { // that reads from cacache and attach it to a new Response const body = new Minipass() const headers = { ...this.policy.responseHeaders() } + const onResume = () => { const cacheStream = cacache.get.stream.byDigest( this.options.cachePath, this.entry.integrity, { memoize: this.options.memoize } @@ -417,6 +424,24 @@ class CacheEntry { } } + for (const name of options.cacheAdditionalHeaders) { + const inMeta = hasOwnProperty(metadata.resHeaders, name) + const inEntry = hasOwnProperty(this.entry.metadata.resHeaders, name) + const inPolicy = hasOwnProperty(this.policy.response.headers, name) + + // if the header is in the existing entry, but it is not in the metadata + // then we need to write it to the metadata as this will refresh the on-disk cache + if (!inMeta && inEntry) { + metadata.resHeaders[name] = this.entry.metadata.resHeaders[name] + } + // if the header is in the metadata, but not in the policy, then we need to set + // it in the policy so that it's included in the immediate response. future + // responses will load a new cache entry, so we don't need to change that + if (!inPolicy && inMeta) { + this.policy.response.headers[name] = metadata.resHeaders[name] + } + } + try { await cacache.index.insert(options.cachePath, this.key, this.entry.integrity, { size: this.entry.size, |