Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 => {
res.headers.set('x-fetch-attempts', attemptNum)
if (opts.integrity) {
remoteFetchHandleIntegrity(res, opts.integrity)
.then(newRes => {
newRes.headers = new fetch.Headers(revalidatedPolicy.policy.responseHeaders())
return newRes
})
}