make-fetch-happen
Advanced tools
Comparing version 9.0.3 to 9.0.4
@@ -51,2 +51,3 @@ const { Request, Response } = require('minipass-fetch') | ||
const metadata = { | ||
time: Date.now(), | ||
url: request.url, | ||
@@ -116,5 +117,14 @@ reqHeaders: {}, | ||
constructor ({ entry, request, response, options }) { | ||
this.entry = entry | ||
if (entry) { | ||
this.key = entry.key | ||
this.entry = entry | ||
// previous versions of this module didn't write an explicit timestamp in | ||
// the metadata, so fall back to the entry's timestamp. we can't use the | ||
// entry timestamp to determine staleness because cacache will update it | ||
// when it verifies its data | ||
this.entry.metadata.time = this.entry.metadata.time || this.entry.time | ||
} else | ||
this.key = cacheKey(request) | ||
this.options = options | ||
this.key = entry ? entry.key : cacheKey(request) | ||
@@ -345,2 +355,6 @@ // these properties are behind getters that lazily evaluate | ||
} catch (err) { | ||
if (err.code === 'EINTEGRITY') | ||
await cacache.rm.content(this.options.cachePath, this.entry.integrity, { memoize: this.options.memoize }) | ||
if (err.code === 'ENOENT' || err.code === 'EINTEGRITY') | ||
await CacheEntry.invalidate(this.request, this.options) | ||
body.emit('error', err) | ||
@@ -352,3 +366,11 @@ } | ||
const cacheStream = cacache.get.stream.byDigest(this.options.cachePath, this.entry.integrity, { memoize: this.options.memoize }) | ||
cacheStream.on('error', (err) => body.emit('error', err)) | ||
cacheStream.on('error', async (err) => { | ||
cacheStream.pause() | ||
if (err.code === 'EINTEGRITY') | ||
await cacache.rm.content(this.options.cachePath, this.entry.integrity, { memoize: this.options.memoize }) | ||
if (err.code === 'ENOENT' || err.code === 'EINTEGRITY') | ||
await CacheEntry.invalidate(this.request, this.options) | ||
body.emit('error', err) | ||
cacheStream.resume() | ||
}) | ||
cacheStream.pipe(body) | ||
@@ -375,3 +397,3 @@ } | ||
response.headers.set('x-local-cache-status', status) | ||
response.headers.set('x-local-cache-time', new Date(this.entry.time).toUTCString()) | ||
response.headers.set('x-local-cache-time', new Date(this.entry.metadata.time).toUTCString()) | ||
return response | ||
@@ -378,0 +400,0 @@ } |
@@ -70,3 +70,3 @@ const CacheSemantics = require('http-cache-semantics') | ||
// cache entry is likely to always identify itself as stale | ||
this.policy._responseTime = this.entry.time | ||
this.policy._responseTime = this.entry.metadata.time | ||
} | ||
@@ -73,0 +73,0 @@ } |
@@ -17,2 +17,3 @@ const Minipass = require('minipass') | ||
'ETIMEDOUT', // someone in the transaction is WAY TOO SLOW | ||
'ERR_SOCKET_TIMEOUT', // same as above, but this one comes from agentkeepalive | ||
// Known codes we do NOT retry on: | ||
@@ -19,0 +20,0 @@ // ENOTFOUND (getaddrinfo failure. Either bad hostname, or offline) |
{ | ||
"name": "make-fetch-happen", | ||
"version": "9.0.3", | ||
"version": "9.0.4", | ||
"description": "Opinionated, caching, retrying fetch client", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
57606
1006