Skip to content
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 lookup option to Client, Pool and Agent (#2440) #3139

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/docs/api/Client.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Every Tls option, see [here](https://nodejs.org/api/tls.html#tls_tls_connect_opt
Furthermore, the following options can be passed:

* **socketPath** `string | null` (optional) - Default: `null` - An IPC endpoint, either Unix domain socket or Windows named pipe.
* **lookup** `Function` (optional) - Custom lookup function. Default: [dns.lookup()](https://nodejs.org/api/dns.html#dnslookuphostname-options-callback).
* **maxCachedSessions** `number | null` (optional) - Default: `100` - Maximum number of TLS cached sessions. Use 0 to disable TLS session caching. Default: 100.
* **timeout** `number | null` (optional) - In milliseconds, Default `10e3`.
* **servername** `string | null` (optional)
Expand Down
1 change: 1 addition & 0 deletions lib/dispatcher/agent.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class Agent extends DispatcherBase {
this[kOptions].interceptors = options.interceptors
? { ...options.interceptors }
: undefined
this[kOptions].lookup = options.lookup
this[kMaxRedirections] = maxRedirections
this[kFactory] = factory
this[kClients] = new Map()
Expand Down
2 changes: 2 additions & 0 deletions lib/dispatcher/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ class Client extends DispatcherBase {
maxResponseSize,
autoSelectFamily,
autoSelectFamilyAttemptTimeout,
lookup,
// h2
maxConcurrentStreams,
allowH2
Expand Down Expand Up @@ -202,6 +203,7 @@ class Client extends DispatcherBase {
maxCachedSessions,
allowH2,
socketPath,
lookup,
timeout: connectTimeout,
...(autoSelectFamily ? { autoSelectFamily, autoSelectFamilyAttemptTimeout } : undefined),
...connect
Expand Down
2 changes: 2 additions & 0 deletions lib/dispatcher/pool.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class Pool extends PoolBase {
autoSelectFamily,
autoSelectFamilyAttemptTimeout,
allowH2,
lookup,
...options
} = {}) {
super()
Expand All @@ -57,6 +58,7 @@ class Pool extends PoolBase {
maxCachedSessions,
allowH2,
socketPath,
lookup,
timeout: connectTimeout,
...(autoSelectFamily ? { autoSelectFamily, autoSelectFamilyAttemptTimeout } : undefined),
...connect
Expand Down
4 changes: 4 additions & 0 deletions test/types/client.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Duplex, Readable, Writable } from 'stream'
import { expectAssignable } from 'tsd'
import { Client, Dispatcher } from '../..'
import { URL } from 'url'
import * as dns from 'node:dns'

expectAssignable<Client>(new Client(''))
expectAssignable<Client>(new Client('', {}))
Expand Down Expand Up @@ -41,6 +42,9 @@ expectAssignable<Client>(new Client(new URL('http://localhost'), {}))
expectAssignable<Client>(new Client('', {
socketPath: '/var/run/docker.sock'
}))
expectAssignable<Client>(new Client('', {
lookup: dns.lookup
}))
expectAssignable<Client>(new Client('', {
pipelining: 1
}))
Expand Down
3 changes: 3 additions & 0 deletions types/client.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import * as dns from "node:dns";
import { URL } from 'url'
import { TlsOptions } from 'tls'
import Dispatcher from './dispatcher'
Expand Down Expand Up @@ -60,6 +61,8 @@ export declare namespace Client {
keepAliveTimeoutThreshold?: number;
/** TODO */
socketPath?: string;
/** Custom DNS lookup function. Default: dns.lookup(). */
lookup?: Omit<typeof dns.lookup, '__promisify__'>;
/** The amount of concurrent requests to be sent over the single TCP/TLS connection according to [RFC7230](https://tools.ietf.org/html/rfc7230#section-6.3.2). Default: `1`. */
pipelining?: number;
/** @deprecated use the connect option instead */
Expand Down