New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: add dns cache #2440 #2552
base: main
Are you sure you want to change the base?
Changes from 13 commits
9413807
5170763
65cc4fc
dffb510
d28dc26
0b0ca32
9a8ea6e
14e986b
007872f
7940b9a
3db9550
afd92c8
30ef32b
67c132f
4f603a6
3c4487b
b192a0e
bbff8e2
13616d3
76e34bb
8ee39e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -165,3 +165,6 @@ module.exports.MockClient = MockClient | |
module.exports.MockPool = MockPool | ||
module.exports.MockAgent = MockAgent | ||
module.exports.mockErrors = mockErrors | ||
|
||
const DNSResolver = require('./lib/dns-resolver') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Move this to the top |
||
module.exports.DNSResolver = DNSResolver |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ const Pool = require('./pool') | |
const Client = require('./client') | ||
const util = require('./core/util') | ||
const createRedirectInterceptor = require('./interceptor/redirectInterceptor') | ||
const DNSResolver = require('./dns-resolver') | ||
|
||
const kOnConnect = Symbol('onConnect') | ||
const kOnDisconnect = Symbol('onDisconnect') | ||
|
@@ -22,6 +23,18 @@ function defaultFactory (origin, opts) { | |
: new Pool(origin, opts) | ||
} | ||
|
||
function getDNSResolver (options) { | ||
if (options?.dnsResolverOptions?.disable) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if it would be a better DX to have |
||
return undefined | ||
antoinegomez marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
if (options.DNSResolver && typeof options.DNSResolver.lookup === 'function') { | ||
return options.DNSResolver | ||
} | ||
|
||
return new DNSResolver(options.dnsResolverOptions) | ||
} | ||
|
||
class Agent extends DispatcherBase { | ||
constructor ({ factory = defaultFactory, maxRedirections = 0, connect, ...options } = {}) { | ||
super() | ||
|
@@ -50,6 +63,7 @@ class Agent extends DispatcherBase { | |
this[kOptions].interceptors = options.interceptors | ||
? { ...options.interceptors } | ||
: undefined | ||
this[kOptions].dnsResolver = getDNSResolver(options) | ||
this[kMaxRedirections] = maxRedirections | ||
this[kFactory] = factory | ||
this[kClients] = new Map() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be called
scheduling
. What doesfirst
vsrandom
do?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done