Skip to content

Commit feb4446

Browse files
nlflukekarrys
authored andcommitted
1 parent 716a07f commit feb4446

File tree

7 files changed

+91
-29
lines changed

7 files changed

+91
-29
lines changed

node_modules/make-fetch-happen/lib/agent.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
const LRU = require('lru-cache')
33
const url = require('url')
44
const isLambda = require('is-lambda')
5+
const dns = require('./dns.js')
56

67
const AGENT_CACHE = new LRU({ max: 50 })
78
const HttpAgent = require('agentkeepalive')
@@ -77,11 +78,13 @@ function getAgent (uri, opts) {
7778
rejectUnauthorized: opts.rejectUnauthorized,
7879
timeout: agentTimeout,
7980
freeSocketTimeout: 15000,
81+
lookup: dns.getLookup(opts.dns),
8082
}) : new HttpAgent({
8183
maxSockets: agentMaxSockets,
8284
localAddress: opts.localAddress,
8385
timeout: agentTimeout,
8486
freeSocketTimeout: 15000,
87+
lookup: dns.getLookup(opts.dns),
8588
})
8689
AGENT_CACHE.set(key, agent)
8790
return agent
@@ -171,6 +174,8 @@ const HttpsProxyAgent = require('https-proxy-agent')
171174
const SocksProxyAgent = require('socks-proxy-agent')
172175
module.exports.getProxy = getProxy
173176
function getProxy (proxyUrl, opts, isHttps) {
177+
// our current proxy agents do not support an overridden dns lookup method, so will not
178+
// benefit from the dns cache
174179
const popts = {
175180
host: proxyUrl.hostname,
176181
port: proxyUrl.port,

node_modules/make-fetch-happen/lib/cache/index.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ const cacheFetch = async (request, options) => {
1414

1515
// otherwise, we make a request, store it and return it
1616
const response = await remote(request, options)
17-
const entry = new CacheEntry({ request, response, options })
18-
return entry.store('miss')
17+
const newEntry = new CacheEntry({ request, response, options })
18+
return newEntry.store('miss')
1919
}
2020

2121
// we have a cached response that satisfies this request, however if the cache
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
const LRUCache = require('lru-cache')
2+
const dns = require('dns')
3+
4+
const defaultOptions = exports.defaultOptions = {
5+
family: undefined,
6+
hints: dns.ADDRCONFIG,
7+
all: false,
8+
verbatim: true,
9+
}
10+
11+
const lookupCache = exports.lookupCache = new LRUCache({ max: 50 })
12+
13+
// this is a factory so that each request can have its own opts (i.e. ttl)
14+
// while still sharing the cache across all requests
15+
exports.getLookup = (dnsOptions) => {
16+
return (hostname, options, callback) => {
17+
if (typeof options === 'function') {
18+
callback = options
19+
options = null
20+
} else if (typeof options === 'number') {
21+
options = { family: options }
22+
}
23+
24+
options = { ...defaultOptions, ...options }
25+
26+
const key = JSON.stringify({
27+
hostname,
28+
family: options.family,
29+
hints: options.hints,
30+
all: options.all,
31+
verbatim: options.verbatim,
32+
})
33+
34+
if (lookupCache.has(key)) {
35+
const [address, family] = lookupCache.get(key)
36+
process.nextTick(callback, null, address, family)
37+
return
38+
}
39+
40+
dnsOptions.lookup(hostname, options, (err, address, family) => {
41+
if (err) {
42+
return callback(err)
43+
}
44+
45+
lookupCache.set(key, [address, family], { ttl: dnsOptions.ttl })
46+
return callback(null, address, family)
47+
})
48+
}
49+
}

node_modules/make-fetch-happen/lib/options.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
const dns = require('dns')
2+
13
const conditionalHeaders = [
24
'if-modified-since',
35
'if-none-match',
@@ -26,6 +28,8 @@ const configureOptions = (opts) => {
2628
options.retry = { retries: 0, ...options.retry }
2729
}
2830

31+
options.dns = { ttl: 5 * 60 * 1000, lookup: dns.lookup, ...options.dns }
32+
2933
options.cache = options.cache || 'default'
3034
if (options.cache === 'default') {
3135
const hasConditionalHeader = Object.keys(options.headers || {}).some((name) => {
Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "make-fetch-happen",
3-
"version": "10.0.6",
3+
"version": "10.1.0",
44
"description": "Opinionated, caching, retrying fetch client",
55
"main": "lib/index.js",
66
"files": [
7-
"bin",
8-
"lib"
7+
"bin/",
8+
"lib/"
99
],
1010
"scripts": {
1111
"preversion": "npm test",
@@ -14,13 +14,16 @@
1414
"test": "tap",
1515
"posttest": "npm run lint",
1616
"eslint": "eslint",
17-
"lint": "eslint '**/*.js'",
17+
"lint": "eslint \"**/*.js\"",
1818
"lintfix": "npm run lint -- --fix",
19-
"postlint": "npm-template-check",
19+
"postlint": "template-oss-check",
2020
"snap": "tap",
21-
"template-copy": "npm-template-copy --force"
21+
"template-oss-apply": "template-oss-apply --force"
22+
},
23+
"repository": {
24+
"type": "git",
25+
"url": "https://github.com/npm/make-fetch-happen.git"
2226
},
23-
"repository": "https://github.com/npm/make-fetch-happen",
2427
"keywords": [
2528
"http",
2629
"request",
@@ -34,12 +37,12 @@
3437
"license": "ISC",
3538
"dependencies": {
3639
"agentkeepalive": "^4.2.1",
37-
"cacache": "^16.0.0",
40+
"cacache": "^16.0.2",
3841
"http-cache-semantics": "^4.1.0",
3942
"http-proxy-agent": "^5.0.0",
4043
"https-proxy-agent": "^5.0.0",
4144
"is-lambda": "^1.0.1",
42-
"lru-cache": "^7.5.1",
45+
"lru-cache": "^7.7.1",
4346
"minipass": "^3.1.6",
4447
"minipass-collect": "^1.0.2",
4548
"minipass-fetch": "^2.0.3",
@@ -51,24 +54,25 @@
5154
"ssri": "^8.0.1"
5255
},
5356
"devDependencies": {
54-
"@npmcli/template-oss": "^2.9.2",
55-
"eslint": "^8.11.0",
57+
"@npmcli/eslint-config": "^3.0.1",
58+
"@npmcli/template-oss": "3.1.2",
5659
"mkdirp": "^1.0.4",
5760
"nock": "^13.2.4",
5861
"rimraf": "^3.0.2",
5962
"safe-buffer": "^5.2.1",
6063
"standard-version": "^9.3.2",
61-
"tap": "^15.1.6"
64+
"tap": "^16.0.0"
6265
},
6366
"engines": {
64-
"node": "^12.13.0 || ^14.15.0 || >=16"
67+
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
6568
},
6669
"tap": {
6770
"color": 1,
6871
"files": "test/*.js",
6972
"check-coverage": true
7073
},
7174
"templateOSS": {
72-
"version": "2.9.2"
75+
"//@npmcli/template-oss": "This file is partially managed by @npmcli/template-oss. Edits may be overwritten.",
76+
"version": "3.1.2"
7377
}
7478
}

package-lock.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
"libnpmsearch": "^5.0.2",
125125
"libnpmteam": "^4.0.2",
126126
"libnpmversion": "^3.0.1",
127-
"make-fetch-happen": "^10.0.6",
127+
"make-fetch-happen": "^10.1.0",
128128
"minipass": "^3.1.6",
129129
"minipass-pipeline": "^1.2.4",
130130
"mkdirp": "^1.0.4",
@@ -4858,18 +4858,18 @@
48584858
"peer": true
48594859
},
48604860
"node_modules/make-fetch-happen": {
4861-
"version": "10.0.6",
4862-
"resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-10.0.6.tgz",
4863-
"integrity": "sha512-4Gfh6lV3TLXmj7qz79hBFuvVqjYSMW6v2+sxtdX4LFQU0rK3V/txRjE0DoZb7X0IF3t9f8NO3CxPSWlvdckhVA==",
4861+
"version": "10.1.0",
4862+
"resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-10.1.0.tgz",
4863+
"integrity": "sha512-HeP4QlkadP/Op+hE+Une1070kcyN85FshQObku3/rmzRh4zDcKXA19d2L3AQR6UoaX3uZmhSOpTLH15b1vOFvQ==",
48644864
"inBundle": true,
48654865
"dependencies": {
48664866
"agentkeepalive": "^4.2.1",
4867-
"cacache": "^16.0.0",
4867+
"cacache": "^16.0.2",
48684868
"http-cache-semantics": "^4.1.0",
48694869
"http-proxy-agent": "^5.0.0",
48704870
"https-proxy-agent": "^5.0.0",
48714871
"is-lambda": "^1.0.1",
4872-
"lru-cache": "^7.5.1",
4872+
"lru-cache": "^7.7.1",
48734873
"minipass": "^3.1.6",
48744874
"minipass-collect": "^1.0.2",
48754875
"minipass-fetch": "^2.0.3",
@@ -4881,7 +4881,7 @@
48814881
"ssri": "^8.0.1"
48824882
},
48834883
"engines": {
4884-
"node": "^12.13.0 || ^14.15.0 || >=16"
4884+
"node": "^12.13.0 || ^14.15.0 || >=16.0.0"
48854885
}
48864886
},
48874887
"node_modules/markdown-escapes": {
@@ -14471,17 +14471,17 @@
1447114471
"peer": true
1447214472
},
1447314473
"make-fetch-happen": {
14474-
"version": "10.0.6",
14475-
"resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-10.0.6.tgz",
14476-
"integrity": "sha512-4Gfh6lV3TLXmj7qz79hBFuvVqjYSMW6v2+sxtdX4LFQU0rK3V/txRjE0DoZb7X0IF3t9f8NO3CxPSWlvdckhVA==",
14474+
"version": "10.1.0",
14475+
"resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-10.1.0.tgz",
14476+
"integrity": "sha512-HeP4QlkadP/Op+hE+Une1070kcyN85FshQObku3/rmzRh4zDcKXA19d2L3AQR6UoaX3uZmhSOpTLH15b1vOFvQ==",
1447714477
"requires": {
1447814478
"agentkeepalive": "^4.2.1",
14479-
"cacache": "^16.0.0",
14479+
"cacache": "^16.0.2",
1448014480
"http-cache-semantics": "^4.1.0",
1448114481
"http-proxy-agent": "^5.0.0",
1448214482
"https-proxy-agent": "^5.0.0",
1448314483
"is-lambda": "^1.0.1",
14484-
"lru-cache": "^7.5.1",
14484+
"lru-cache": "^7.7.1",
1448514485
"minipass": "^3.1.6",
1448614486
"minipass-collect": "^1.0.2",
1448714487
"minipass-fetch": "^2.0.3",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@
9191
"libnpmsearch": "^5.0.2",
9292
"libnpmteam": "^4.0.2",
9393
"libnpmversion": "^3.0.1",
94-
"make-fetch-happen": "^10.0.6",
94+
"make-fetch-happen": "^10.1.0",
9595
"minipass": "^3.1.6",
9696
"minipass-pipeline": "^1.2.4",
9797
"mkdirp": "^1.0.4",

0 commit comments

Comments
 (0)