fix(#3817): send servername for SNI on TLS (#3821) [backport] (#3864) · nodejs/undici@a0220f1 (original) (raw)
`@@ -986,6 +986,57 @@ client.dispatch(
`
986
986
`);
`
987
987
```` ```
`988`
`988`
``
``
`989`
`` +
##### `dns`
``
``
`990`
`+`
``
`991`
`` +
The `dns` interceptor enables you to cache DNS lookups for a given duration, per origin.
``
``
`992`
`+`
``
`993`
`+
>It is well suited for scenarios where you want to cache DNS lookups to avoid the overhead of resolving the same domain multiple times
`
``
`994`
`+`
``
`995`
`+
**Options**
`
``
`996`
`` +
- `maxTTL` - The maximum time-to-live (in milliseconds) of the DNS cache. It should be a positive integer. Default: `10000`.
``
``
`997`
`` +
- Set `0` to disable TTL.
``
``
`998`
`` +
- `maxItems` - The maximum number of items to cache. It should be a positive integer. Default: `Infinity`.
``
``
`999`
`` +
- `dualStack` - Whether to resolve both IPv4 and IPv6 addresses. Default: `true`.
``
``
`1000`
`+
- It will also attempt a happy-eyeballs-like approach to connect to the available addresses in case of a connection failure.
`
``
`1001`
`` +
- `affinity` - Whether to use IPv4 or IPv6 addresses. Default: `4`.
``
``
`1002`
`` +
- It can be either `'4` or `6`.
``
``
`1003`
`` +
- It will only take effect if `dualStack` is `false`.
``
``
`1004`
`` +
- `lookup: (hostname: string, options: LookupOptions, callback: (err: NodeJS.ErrnoException | null, addresses: DNSInterceptorRecord[]) => void) => void` - Custom lookup function. Default: `dns.lookup`.
``
``
`1005`
`+
- For more info see [dns.lookup](https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback).
`
``
`1006`
`` +
- `pick: (origin: URL, records: DNSInterceptorRecords, affinity: 4 | 6) => DNSInterceptorRecord` - Custom pick function. Default: `RoundRobin`.
``
``
`1007`
`+
- The function should return a single record from the records array.
`
``
`1008`
`+
- By default a simplified version of Round Robin is used.
`
``
`1009`
`` +
- The `records` property can be mutated to store the state of the balancing algorithm.
``
``
`1010`
`+`
``
`1011`
`` +
> The `Dispatcher#options` also gets extended with the options `dns.affinity`, `dns.dualStack`, `dns.lookup` and `dns.pick` which can be used to configure the interceptor at a request-per-request basis.
``
``
`1012`
`+`
``
`1013`
`+`
``
`1014`
`+
**DNSInterceptorRecord**
`
``
`1015`
`+
It represents a DNS record.
`
``
`1016`
`` +
- `family` - (`number`) The IP family of the address. It can be either `4` or `6`.
``
``
`1017`
`` +
- `address` - (`string`) The IP address.
``
``
`1018`
`+`
``
`1019`
`+
**DNSInterceptorOriginRecords**
`
``
`1020`
`+
It represents a map of DNS IP addresses records for a single origin.
`
``
`1021`
`` +
- `4.ips` - (`DNSInterceptorRecord[] | null`) The IPv4 addresses.
``
``
`1022`
`` +
- `6.ips` - (`DNSInterceptorRecord[] | null`) The IPv6 addresses.
``
``
`1023`
`+`
``
`1024`
`+
**Example - Basic DNS Interceptor**
`
``
`1025`
`+`
``
`1026`
```` +
```js
``
1027
`+
const { Client, interceptors } = require("undici");
`
``
1028
`+
const { dns } = interceptors;
`
``
1029
+
``
1030
`+
const client = new Agent().compose([
`
``
1031
`+
dns({ ...opts })
`
``
1032
`+
])
`
``
1033
+
``
1034
`+
const response = await client.request({
`
``
1035
`` +
origin: http://localhost:3030,
``
``
1036
`+
...requestOpts
`
``
1037
`+
})
`
``
1038
```
``
1039
+
989
1040
`` ##### Response Error Interceptor
``
990
1041
``
991
1042
`Introduction
`