Socket
Socket
Sign inDemoInstall

make-fetch-happen

Package Overview
Dependencies
20
Maintainers
4
Versions
105
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 8.0.10 to 8.0.11

52

agent.js

@@ -41,3 +41,3 @@ 'use strict'

`timeout:${agentTimeout}`,
`maxSockets:${agentMaxSockets}`
`maxSockets:${agentMaxSockets}`,
].join(':')

@@ -52,11 +52,9 @@

: isHttps ? require('https').globalAgent
: require('http').globalAgent
: require('http').globalAgent
if (isLambda && !pxuri) {
if (isLambda && !pxuri)
return lambdaAgent
}
if (AGENT_CACHE.peek(key)) {
if (AGENT_CACHE.peek(key))
return AGENT_CACHE.get(key)
}

@@ -66,3 +64,3 @@ if (pxuri) {

...opts,
agent: lambdaAgent
agent: lambdaAgent,
} : opts

@@ -86,7 +84,7 @@ const proxy = getProxy(pxuri, pxopts, isHttps)

rejectUnauthorized: opts.strictSSL,
timeout: agentTimeout
timeout: agentTimeout,
}) : new HttpAgent({
maxSockets: agentMaxSockets,
localAddress: opts.localAddress,
timeout: agentTimeout
timeout: agentTimeout,
})

@@ -100,12 +98,12 @@ AGENT_CACHE.set(key, agent)

let noproxy = (opts.noProxy || getProcessEnv('no_proxy'))
if (typeof noproxy === 'string') {
if (typeof noproxy === 'string')
noproxy = noproxy.split(/\s*,\s*/g)
}
return noproxy && noproxy.some(no => {
const noParts = no.split('.').filter(x => x).reverse()
if (!noParts.length) { return false }
if (!noParts.length)
return false
for (let i = 0; i < noParts.length; i++) {
if (host[i] !== noParts[i]) {
if (host[i] !== noParts[i])
return false
}
}

@@ -119,5 +117,4 @@ return true

function getProcessEnv (env) {
if (!env) {
if (!env)
return
}

@@ -131,3 +128,4 @@ let value

process.env[e.toLowerCase()]
if (typeof value !== 'undefined') { break }
if (typeof value !== 'undefined')
break
}

@@ -158,3 +156,4 @@ }

)
if (!proxy) { return null }
if (!proxy)
return null

@@ -168,4 +167,4 @@ const parsedProxy = (typeof proxy === 'string') ? new url.URL(proxy) : proxy

u.username && u.password ? `${u.username}:${u.password}`
: u.username ? u.username
: null
: u.username ? u.username
: null

@@ -191,3 +190,3 @@ const getPath = u => u.pathname + u.search + u.hash

maxSockets: getMaxSockets(opts.maxSockets),
rejectUnauthorized: opts.strictSSL
rejectUnauthorized: opts.strictSSL,
}

@@ -197,11 +196,9 @@

if (!isHttps) {
if (!HttpProxyAgent) {
if (!HttpProxyAgent)
HttpProxyAgent = require('http-proxy-agent')
}
return new HttpProxyAgent(popts)
} else {
if (!HttpsProxyAgent) {
if (!HttpsProxyAgent)
HttpsProxyAgent = require('https-proxy-agent')
}

@@ -211,5 +208,4 @@ return new HttpsProxyAgent(popts)

} else if (proxyUrl.protocol.startsWith('socks')) {
if (!SocksProxyAgent) {
if (!SocksProxyAgent)
SocksProxyAgent = require('socks-proxy-agent')
}

@@ -221,3 +217,3 @@ return new SocksProxyAgent(popts)

{
url: proxyUrl.href
url: proxyUrl.href,
}

@@ -224,0 +220,0 @@ )

@@ -15,2 +15,16 @@ 'use strict'

// some headers should never be stored in the cache, either because
// they're a security footgun to leave lying around, or because we
// just don't need them taking up space.
// set to undefined so they're omitted from the JSON.stringify
const pruneHeaders = {
authorization: undefined,
'npm-session': undefined,
'set-cookie': undefined,
'cf-ray': undefined,
'cf-cache-status': undefined,
'cf-request-id': undefined,
'x-fetch-attempts': undefined,
}
function cacheKey (req) {

@@ -24,3 +38,4 @@ const parsed = new url.URL(req.url)

hostname: parsed.hostname,
pathname: parsed.pathname
pathname: parsed.pathname,
search: parsed.search,
})

@@ -40,2 +55,7 @@ }`

static get pruneHeaders () {
// exposed for testing, not modifiable
return { ...pruneHeaders }
}
// Returns a Promise that resolves to the response associated with the first

@@ -55,3 +75,3 @@ // matching request in the Cache object.

cacheIntegrity: info.integrity,
integrity: opts && opts.integrity
integrity: opts && opts.integrity,
})) {

@@ -64,3 +84,3 @@ const resHeaders = new fetch.Headers(info.metadata.resHeaders)

headers: resHeaders,
status: 200
status: 200,
})

@@ -78,3 +98,3 @@ }

const c = cacache.get.stream.byDigest(cachePath, info.integrity, {
memoize: opts.memoize
memoize: opts.memoize,
})

@@ -89,3 +109,3 @@ c.on('error', /* istanbul ignore next */ err => {

cacache.get.byDigest(cachePath, info.integrity, {
memoize: opts.memoize
memoize: opts.memoize,
})

@@ -103,3 +123,3 @@ .then(data => body.end(data))

status: 200,
size: info.size
size: info.size,
}))

@@ -120,7 +140,13 @@ }

url: req.url,
reqHeaders: req.headers.raw(),
resHeaders: response.headers.raw()
reqHeaders: {
...req.headers.raw(),
...pruneHeaders,
},
resHeaders: {
...response.headers.raw(),
...pruneHeaders,
},
},
size,
memoize: fitInMemory && opts.memoize
memoize: fitInMemory && opts.memoize,
}

@@ -153,3 +179,3 @@ if (req.method === 'HEAD' || response.status === 304) {

return cacheWritePromise
}
},
}))

@@ -197,7 +223,7 @@

if (typeof opts.memoize === 'object') {
if (opts.memoize.reset) {
if (opts.memoize.reset)
opts.memoize.reset()
} else if (opts.memoize.clear) {
else if (opts.memoize.clear)
opts.memoize.clear()
} else {
else {
Object.keys(opts.memoize).forEach(k => {

@@ -222,16 +248,15 @@ opts.memoize[k] = null

if (vary) {
if (vary.match(/\*/)) {
if (vary.match(/\*/))
return false
} else {
else {
const fieldsMatch = vary.split(/\s*,\s*/).every(field => {
return cached.reqHeaders.get(field) === req.headers.get(field)
})
if (!fieldsMatch) {
if (!fieldsMatch)
return false
}
}
}
if (cached.integrity) {
if (cached.integrity)
return ssri.parse(cached.integrity).match(cached.cacheIntegrity)
}
reqUrl.hash = null

@@ -238,0 +263,0 @@ cacheUrl.hash = null

@@ -25,3 +25,3 @@ 'use strict'

'EADDRINUSE', // failed to bind to a local port (proxy?)
'ETIMEDOUT' // someone in the transaction is WAY TOO SLOW
'ETIMEDOUT', // someone in the transaction is WAY TOO SLOW
// Known codes we do NOT retry on:

@@ -32,3 +32,3 @@ // ENOTFOUND (getaddrinfo failure. Either bad hostname, or offline)

const RETRY_TYPES = [
'request-timeout'
'request-timeout',
]

@@ -61,3 +61,3 @@

method: opts.method,
headers: opts.headers
headers: opts.headers,
})

@@ -69,5 +69,4 @@ return opts.cacheManager.delete(req, opts)

function initializeSsri () {
if (!ssri) {
if (!ssri)
ssri = require('ssri')
}
}

@@ -97,3 +96,3 @@

method: opts.method,
headers: opts.headers
headers: opts.headers,
})

@@ -118,9 +117,7 @@

if (opts.cache === 'default' && !isStale(req, res)) {
if (opts.cache === 'default' && !isStale(req, res))
return res
}
if (opts.cache === 'default' || opts.cache === 'no-cache') {
if (opts.cache === 'default' || opts.cache === 'no-cache')
return conditionalFetch(req, res, opts)
}

@@ -159,3 +156,3 @@ if (opts.cache === 'force-cache' || opts.cache === 'only-if-cached') {

method: req.method,
headers: iterableToObject(req.headers)
headers: iterableToObject(req.headers),
}

@@ -192,3 +189,3 @@

method: req.method,
headers: Object.assign({}, opts.headers || {})
headers: Object.assign({}, opts.headers || {}),
}

@@ -203,3 +200,3 @@

status: condRes.status,
headers: iterableToObject(condRes.headers)
headers: iterableToObject(condRes.headers),
})

@@ -228,8 +225,8 @@

.filter(k => !newHeaders[k])
for (const key of toDelete) {
for (const key of toDelete)
newRes.headers.delete(key)
}
for (const [key, val] of Object.entries(newHeaders)) {
for (const [key, val] of Object.entries(newHeaders))
newRes.headers.set(key, val)
}
return newRes

@@ -243,5 +240,5 @@ })

.catch(err => {
if (mustRevalidate(cachedRes)) {
if (mustRevalidate(cachedRes))
throw err
} else {
else {
// 111 Revalidation failed

@@ -270,8 +267,8 @@ // MUST be included if a cache returns a stale response because an

function remoteFetchHandleIntegrity (res, integrity) {
if (res.status !== 200) {
if (res.status !== 200)
return res // Error responses aren't subject to integrity checks.
}
const oldBod = res.body
const newBod = ssri.integrityStream({
integrity
integrity,
})

@@ -286,8 +283,7 @@ return new fetch.Response(new MinipassPipeline(oldBod, newBod), res)

: new fetch.Headers(opts.headers)
if (!headers.get('connection')) {
if (!headers.get('connection'))
headers.set('connection', agent ? 'keep-alive' : 'close')
}
if (!headers.get('user-agent')) {
if (!headers.get('user-agent'))
headers.set('user-agent', USER_AGENT)
}

@@ -304,3 +300,3 @@ const reqOpts = {

counter: opts.counter,
timeout: opts.timeout
timeout: opts.timeout,
}

@@ -313,5 +309,4 @@

.then((res) => {
if (opts.integrity) {
if (opts.integrity)
res = remoteFetchHandleIntegrity(res, opts.integrity)
}

@@ -335,5 +330,4 @@ res.headers.set('x-fetch-attempts', attemptNum)

if (isCachable) {
if (isCachable)
return opts.cacheManager.put(req, res, opts)
}

@@ -343,5 +337,4 @@ if (!isMethodGetHead) {

if (res.status >= 500 && req.method !== 'POST' && !isStream) {
if (typeof opts.onRetry === 'function') {
if (typeof opts.onRetry === 'function')
opts.onRetry(res)
}

@@ -368,5 +361,4 @@ return retryHandler(res)

if (isRetriable) {
if (typeof opts.onRetry === 'function') {
if (typeof opts.onRetry === 'function')
opts.onRetry(res)
}

@@ -376,8 +368,8 @@ return retryHandler(res)

if (!fetch.isRedirect(res.status)) {
if (!fetch.isRedirect(res.status))
return res
}
if (opts.redirect === 'manual') {
if (opts.redirect === 'manual')
return res
}
// if (!fetch.isRedirect(res.status) || opts.redirect === 'manual') {

@@ -424,5 +416,4 @@ // return res

// https://github.com/request/request/blob/b12a6245/lib/redirect.js#L134-L138
if (new url.URL(req.url).hostname !== redirectURL.hostname) {
if (new url.URL(req.url).hostname !== redirectURL.hostname)
req.headers.delete('authorization')
}

@@ -464,9 +455,7 @@ // for POST request with 301/302 response, or any request with 303 response,

if (req.method === 'POST' || isRetryError) {
if (req.method === 'POST' || isRetryError)
throw err
}
if (typeof opts.onRetry === 'function') {
if (typeof opts.onRetry === 'function')
opts.onRetry(err)
}

@@ -473,0 +462,0 @@ return retryHandler(err)

{
"name": "make-fetch-happen",
"version": "8.0.10",
"version": "8.0.11",
"description": "Opinionated, caching, retrying fetch client",

@@ -17,3 +17,5 @@ "main": "index.js",

"posttest": "npm run lint",
"lint": "standard"
"eslint": "eslint",
"lint": "npm run eslint -- *.js utils test",
"lintfix": "npm run lint -- --fix"
},

@@ -37,5 +39,10 @@ "repository": "https://github.com/npm/make-fetch-happen",

"dependencies": {
"agentkeepalive": "^4.1.0",
"cacache": "^15.0.0",
"http-cache-semantics": "^4.0.4",
"agentkeepalive": "^4.1.3",
"cacache": "^15.0.5",
"eslint": "^7.14.0",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1",
"eslint-plugin-standard": "^5.0.0",
"http-cache-semantics": "^4.1.0",
"http-proxy-agent": "^4.0.1",

@@ -47,5 +54,5 @@ "https-proxy-agent": "^5.0.0",

"minipass-collect": "^1.0.2",
"minipass-fetch": "^1.3.0",
"minipass-fetch": "^1.3.2",
"minipass-flush": "^1.0.5",
"minipass-pipeline": "^1.2.2",
"minipass-pipeline": "^1.2.4",
"promise-retry": "^1.1.1",

@@ -56,3 +63,3 @@ "socks-proxy-agent": "^5.0.0",

"devDependencies": {
"mkdirp": "^1.0.3",
"mkdirp": "^1.0.4",
"nock": "^11.9.1",

@@ -62,7 +69,5 @@ "npmlog": "^4.1.2",

"rimraf": "^2.7.1",
"safe-buffer": "^5.2.0",
"standard": "^14.3.1",
"safe-buffer": "^5.2.1",
"standard-version": "^7.1.0",
"tacks": "^1.2.6",
"tap": "^14.10.6"
"tap": "^14.11.0"
},

@@ -69,0 +74,0 @@ "engines": {

@@ -15,5 +15,5 @@ 'use strict'

// Shorthand
if (typeof opts.retry === 'number') {
if (typeof opts.retry === 'number')
opts.retry = { retries: opts.retry }
}
if (typeof opts.retry === 'string') {

@@ -29,7 +29,6 @@ const value = parseInt(opts.retry, 10)

if (opts.cacheManager) {
if (opts.cacheManager)
initializeCache(opts)
}
return opts
}
'use strict'
module.exports = function isHeaderConditional (headers) {
if (!headers || typeof headers !== 'object') {
if (!headers || typeof headers !== 'object')
return false
}

@@ -13,3 +12,3 @@ const modifiers = [

'if-match',
'if-range'
'if-range',
]

@@ -16,0 +15,0 @@

@@ -5,6 +5,6 @@ 'use strict'

const obj = {}
for (const k of iter.keys()) {
for (const k of iter.keys())
obj[k] = iter.get(k)
}
return obj
}

@@ -11,7 +11,7 @@ 'use strict'

method: req.method,
headers: iterableToObject(req.headers)
headers: iterableToObject(req.headers),
}
const _res = {
status: res.status,
headers: iterableToObject(res.headers)
headers: iterableToObject(res.headers),
}

@@ -18,0 +18,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc