Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}).then(info => {
if (info && info.metadata && matchDetails(req, {
url: info.metadata.url,
reqHeaders: new fetch.Headers(info.metadata.reqHeaders),
resHeaders: new fetch.Headers(info.metadata.resHeaders),
cacheIntegrity: info.integrity,
integrity: opts && opts.integrity
})) {
const resHeaders = new fetch.Headers(info.metadata.resHeaders)
addCacheHeaders(resHeaders, this._path, key, info.integrity, info.time)
if (req.method === 'HEAD') {
return new fetch.Response(null, {
url: req.url,
headers: resHeaders,
status: 200
})
}
const cachePath = this._path
// avoid opening cache file handles until a user actually tries to
// read from it.
const body = new Minipass()
const fitInMemory = info.size < MAX_MEM_SIZE
const removeOnResume = () => body.removeListener('resume', onResume)
const onResume =
opts.memoize !== false && fitInMemory
}).then(info => {
if (info && info.metadata && matchDetails(req, {
url: info.metadata.url,
reqHeaders: new fetch.Headers(info.metadata.reqHeaders),
resHeaders: new fetch.Headers(info.metadata.resHeaders),
cacheIntegrity: info.integrity,
integrity: opts && opts.integrity
})) {
const resHeaders = new fetch.Headers(info.metadata.resHeaders)
addCacheHeaders(resHeaders, this._path, key, info.integrity, info.time)
if (req.method === 'HEAD') {
return new fetch.Response(null, {
url: req.url,
headers: resHeaders,
status: 200
})
}
const cachePath = this._path
// avoid opening cache file handles until a user actually tries to
// read from it.
}).then(info => {
if (info && info.metadata && matchDetails(req, {
url: info.metadata.url,
reqHeaders: new fetch.Headers(info.metadata.reqHeaders),
resHeaders: new fetch.Headers(info.metadata.resHeaders),
cacheIntegrity: info.integrity,
integrity: opts && opts.integrity
})) {
const resHeaders = new fetch.Headers(info.metadata.resHeaders)
addCacheHeaders(resHeaders, this._path, key, info.integrity, info.time)
if (req.method === 'HEAD') {
return new fetch.Response(null, {
url: req.url,
headers: resHeaders,
status: 200
})
}
const cachePath = this._path
// avoid opening cache file handles until a user actually tries to
// read from it.
const body = new Minipass()
t.test('validate append headers', (t) => {
const date = JSON.stringify(new Date().toUTCString())
const replace = false
const headers = new Fetch.Headers()
const req = new Fetch.Request(url, { headers })
const origHeaderAppend = req.headers.append
req.headers.append = (...args) => {
const expectedValue = `999 google.com {"hello":"world"} ${date}`
t.equal('Warning', args[0])
t.same(expectedValue, args[1])
return origHeaderAppend.call(headers, ...args)
}
setWarning(req, code, message, replace)
req.headers.append = origHeaderAppend
t.end()
function remoteFetch (uri, opts) {
const agent = getAgent(uri, opts)
const headers = Object.assign({
connection: agent ? 'keep-alive' : 'close',
'user-agent': USER_AGENT
}, opts.headers || {})
const reqOpts = {
agent,
body: opts.body,
compress: opts.compress,
follow: opts.follow,
headers: new fetch.Headers(headers),
method: opts.method,
redirect: 'manual',
size: opts.size,
counter: opts.counter,
timeout: opts.timeout
}
return retry(
(retryHandler, attemptNum) => {
const req = new fetch.Request(uri, reqOpts)
return fetch(req)
.then((res) => {
if (opts.integrity) {
res = remoteFetchHandleIntegrity(res, opts.integrity)
}