Skip to content

Commit 60d2493

Browse files
mcollinaRafaelGSS
authored andcommitted
deps: update undici to v5.28.4
Signed-off-by: Matteo Collina <hello@matteocollina.com> PR-URL: nodejs-private/node-private#577 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
1 parent 0fb816d commit 60d2493

File tree

104 files changed

+5210
-20964
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

104 files changed

+5210
-20964
lines changed

deps/undici/src/README.md

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,30 +18,34 @@ npm i undici
1818
## Benchmarks
1919

2020
The benchmark is a simple `hello world` [example](benchmarks/benchmark.js) using a
21-
number of unix sockets (connections) with a pipelining depth of 10 running on Node 16.
22-
The benchmarks below have the [simd](https://github.com/WebAssembly/simd) feature enabled.
21+
number of unix sockets (connections) with a pipelining depth of 10 running on Node 20.6.0.
2322

2423
### Connections 1
2524

25+
2626
| Tests | Samples | Result | Tolerance | Difference with slowest |
2727
|---------------------|---------|---------------|-----------|-------------------------|
28-
| http - no keepalive | 15 | 4.63 req/sec | ± 2.77 % | - |
29-
| http - keepalive | 10 | 4.81 req/sec | ± 2.16 % | + 3.94 % |
30-
| undici - stream | 25 | 62.22 req/sec | ± 2.67 % | + 1244.58 % |
31-
| undici - dispatch | 15 | 64.33 req/sec | ± 2.47 % | + 1290.24 % |
32-
| undici - request | 15 | 66.08 req/sec | ± 2.48 % | + 1327.88 % |
33-
| undici - pipeline | 10 | 66.13 req/sec | ± 1.39 % | + 1329.08 % |
28+
| http - no keepalive | 15 | 5.32 req/sec | ± 2.61 % | - |
29+
| http - keepalive | 10 | 5.35 req/sec | ± 2.47 % | + 0.44 % |
30+
| undici - fetch | 15 | 41.85 req/sec | ± 2.49 % | + 686.04 % |
31+
| undici - pipeline | 40 | 50.36 req/sec | ± 2.77 % | + 845.92 % |
32+
| undici - stream | 15 | 60.58 req/sec | ± 2.75 % | + 1037.72 % |
33+
| undici - request | 10 | 61.19 req/sec | ± 2.60 % | + 1049.24 % |
34+
| undici - dispatch | 20 | 64.84 req/sec | ± 2.81 % | + 1117.81 % |
35+
3436

3537
### Connections 50
3638

3739
| Tests | Samples | Result | Tolerance | Difference with slowest |
3840
|---------------------|---------|------------------|-----------|-------------------------|
39-
| http - no keepalive | 50 | 3546.49 req/sec | ± 2.90 % | - |
40-
| http - keepalive | 15 | 5692.67 req/sec | ± 2.48 % | + 60.52 % |
41-
| undici - pipeline | 25 | 8478.71 req/sec | ± 2.62 % | + 139.07 % |
42-
| undici - request | 20 | 9766.66 req/sec | ± 2.79 % | + 175.39 % |
43-
| undici - stream | 15 | 10109.74 req/sec | ± 2.94 % | + 185.06 % |
44-
| undici - dispatch | 25 | 10949.73 req/sec | ± 2.54 % | + 208.75 % |
41+
| undici - fetch | 30 | 2107.19 req/sec | ± 2.69 % | - |
42+
| http - no keepalive | 10 | 2698.90 req/sec | ± 2.68 % | + 28.08 % |
43+
| http - keepalive | 10 | 4639.49 req/sec | ± 2.55 % | + 120.17 % |
44+
| undici - pipeline | 40 | 6123.33 req/sec | ± 2.97 % | + 190.59 % |
45+
| undici - stream | 50 | 9426.51 req/sec | ± 2.92 % | + 347.35 % |
46+
| undici - request | 10 | 10162.88 req/sec | ± 2.13 % | + 382.29 % |
47+
| undici - dispatch | 50 | 11191.11 req/sec | ± 2.98 % | + 431.09 % |
48+
4549

4650
## Quick Start
4751

@@ -432,6 +436,7 @@ and `undici.Agent`) which will enable the family autoselection algorithm when es
432436
* [__Ethan Arrowood__](https://github.com/ethan-arrowood), <https://www.npmjs.com/~ethan_arrowood>
433437
* [__Matteo Collina__](https://github.com/mcollina), <https://www.npmjs.com/~matteo.collina>
434438
* [__Robert Nagy__](https://github.com/ronag), <https://www.npmjs.com/~ronag>
439+
* [__Matthew Aitken__](https://github.com/KhafraDev), <https://www.npmjs.com/~khaf>
435440

436441
## License
437442

deps/undici/src/docs/api/Client.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Returns: `Client`
3333
* **autoSelectFamily**: `boolean` (optional) - Default: depends on local Node version, on Node 18.13.0 and above is `false`. Enables a family autodetection algorithm that loosely implements section 5 of [RFC 8305](https://tools.ietf.org/html/rfc8305#section-5). See [here](https://nodejs.org/api/net.html#socketconnectoptions-connectlistener) for more details. This option is ignored if not supported by the current Node version.
3434
* **autoSelectFamilyAttemptTimeout**: `number` - Default: depends on local Node version, on Node 18.13.0 and above is `250`. The amount of time in milliseconds to wait for a connection attempt to finish before trying the next address when using the `autoSelectFamily` option. See [here](https://nodejs.org/api/net.html#socketconnectoptions-connectlistener) for more details.
3535
* **allowH2**: `boolean` - Default: `false`. Enables support for H2 if the server has assigned bigger priority to it through ALPN negotiation.
36-
* **maxConcurrentStreams**: `number` - Default: `100`. Dictates the maximum number of concurrent streams for a single H2 session. It can be overriden by a SETTINGS remote frame.
36+
* **maxConcurrentStreams**: `number` - Default: `100`. Dictates the maximum number of concurrent streams for a single H2 session. It can be overridden by a SETTINGS remote frame.
3737

3838
#### Parameter: `ConnectOptions`
3939

deps/undici/src/docs/api/Connector.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ Every Tls option, see [here](https://nodejs.org/api/tls.html#tls_tls_connect_opt
1313
Furthermore, the following options can be passed:
1414

1515
* **socketPath** `string | null` (optional) - Default: `null` - An IPC endpoint, either Unix domain socket or Windows named pipe.
16-
* **maxCachedSessions** `number | null` (optional) - Default: `100` - Maximum number of TLS cached sessions. Use 0 to disable TLS session caching. Default: 100.
17-
* **timeout** `number | null` (optional) - Default `10e3`
16+
* **maxCachedSessions** `number | null` (optional) - Default: `100` - Maximum number of TLS cached sessions. Use 0 to disable TLS session caching. Default: `100`.
17+
* **timeout** `number | null` (optional) - In milliseconds. Default `10e3`.
1818
* **servername** `string | null` (optional)
1919

2020
Once you call `buildConnector`, it will return a connector function, which takes the following parameters.

deps/undici/src/docs/api/Dispatcher.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,9 @@ Returns: `Boolean` - `false` if dispatcher is busy and further dispatch calls wo
200200
* **blocking** `boolean` (optional) - Default: `false` - Whether the response is expected to take a long time and would end up blocking the pipeline. When this is set to `true` further pipelining will be avoided on the same connection until headers have been received.
201201
* **upgrade** `string | null` (optional) - Default: `null` - Upgrade the request. Should be used to specify the kind of upgrade i.e. `'Websocket'`.
202202
* **bodyTimeout** `number | null` (optional) - The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Defaults to 300 seconds.
203-
* **headersTimeout** `number | null` (optional) - The amount of time the parser will wait to receive the complete HTTP headers while not sending the request. Defaults to 300 seconds.
203+
* **headersTimeout** `number | null` (optional) - The amount of time, in milliseconds, the parser will wait to receive the complete HTTP headers while not sending the request. Defaults to 300 seconds.
204204
* **throwOnError** `boolean` (optional) - Default: `false` - Whether Undici should throw an error upon receiving a 4xx or 5xx response from the server.
205+
* **expectContinue** `boolean` (optional) - Default: `false` - For H2, it appends the expect: 100-continue header, and halts the request body until a 100-continue is received from the remote server
205206

206207
#### Parameter: `DispatchHandler`
207208

deps/undici/src/docs/api/MockPool.md

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const mockPool = mockAgent.get('http://localhost:3000')
3535

3636
### `MockPool.intercept(options)`
3737

38-
This method defines the interception rules for matching against requests for a MockPool or MockPool. We can intercept multiple times on a single instance.
38+
This method defines the interception rules for matching against requests for a MockPool or MockPool. We can intercept multiple times on a single instance, but each intercept is only used once. For example if you expect to make 2 requests inside a test, you need to call `intercept()` twice. Assuming you use `disableNetConnect()` you will get `MockNotMatchedError` on the second request when you only call `intercept()` once.
3939

4040
When defining interception rules, all the rules must pass for a request to be intercepted. If a request is not intercepted, a real request will be attempted.
4141

@@ -53,11 +53,11 @@ Returns: `MockInterceptor` corresponding to the input options.
5353

5454
### Parameter: `MockPoolInterceptOptions`
5555

56-
* **path** `string | RegExp | (path: string) => boolean` - a matcher for the HTTP request path.
56+
* **path** `string | RegExp | (path: string) => boolean` - a matcher for the HTTP request path. When a `RegExp` or callback is used, it will match against the request path including all query parameters in alphabetical order. When a `string` is provided, the query parameters can be conveniently specified through the `MockPoolInterceptOptions.query` setting.
5757
* **method** `string | RegExp | (method: string) => boolean` - (optional) - a matcher for the HTTP request method. Defaults to `GET`.
5858
* **body** `string | RegExp | (body: string) => boolean` - (optional) - a matcher for the HTTP request body.
5959
* **headers** `Record<string, string | RegExp | (body: string) => boolean`> - (optional) - a matcher for the HTTP request headers. To be intercepted, a request must match all defined headers. Extra headers not defined here may (or may not) be included in the request and do not affect the interception in any way.
60-
* **query** `Record<string, any> | null` - (optional) - a matcher for the HTTP request query string params.
60+
* **query** `Record<string, any> | null` - (optional) - a matcher for the HTTP request query string params. Only applies when a `string` was provided for `MockPoolInterceptOptions.path`.
6161

6262
### Return: `MockInterceptor`
6363

@@ -457,6 +457,41 @@ const result3 = await request('http://localhost:3000/foo')
457457
// Will not match and make attempt a real request
458458
```
459459

460+
#### Example - Mocked request with path callback
461+
462+
```js
463+
import { MockAgent, setGlobalDispatcher, request } from 'undici'
464+
import querystring from 'querystring'
465+
466+
const mockAgent = new MockAgent()
467+
setGlobalDispatcher(mockAgent)
468+
469+
const mockPool = mockAgent.get('http://localhost:3000')
470+
471+
const matchPath = requestPath => {
472+
const [pathname, search] = requestPath.split('?')
473+
const requestQuery = querystring.parse(search)
474+
475+
if (!pathname.startsWith('/foo')) {
476+
return false
477+
}
478+
479+
if (!Object.keys(requestQuery).includes('foo') || requestQuery.foo !== 'bar') {
480+
return false
481+
}
482+
483+
return true
484+
}
485+
486+
mockPool.intercept({
487+
path: matchPath,
488+
method: 'GET'
489+
}).reply(200, 'foo')
490+
491+
const result = await request('http://localhost:3000/foo?foo=bar')
492+
// Will match and return mocked data
493+
```
494+
460495
### `MockPool.close()`
461496

462497
Closes the mock pool and de-registers from associated MockAgent.

deps/undici/src/docs/api/ProxyAgent.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ Extends: [`AgentOptions`](Agent.md#parameter-agentoptions)
1919
* **uri** `string` (required) - It can be passed either by a string or a object containing `uri` as string.
2020
* **token** `string` (optional) - It can be passed by a string of token for authentication.
2121
* **auth** `string` (**deprecated**) - Use token.
22-
* **clientFactory** `(origin: URL, opts: Object) => Dispatcher` - Default: `(origin, opts) => new Pool(origin, opts)`
22+
* **clientFactory** `(origin: URL, opts: Object) => Dispatcher` (optional) - Default: `(origin, opts) => new Pool(origin, opts)`
23+
* **requestTls** `BuildOptions` (optional) - Options object passed when creating the underlying socket via the connector builder for the request. See [TLS](https://nodejs.org/api/tls.html#tlsconnectoptions-callback).
24+
* **proxyTls** `BuildOptions` (optional) - Options object passed when creating the underlying socket via the connector builder for the proxy server. See [TLS](https://nodejs.org/api/tls.html#tlsconnectoptions-callback).
2325

2426
Examples:
2527

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
# Class: RetryHandler
2+
3+
Extends: `undici.DispatcherHandlers`
4+
5+
A handler class that implements the retry logic for a request.
6+
7+
## `new RetryHandler(dispatchOptions, retryHandlers, [retryOptions])`
8+
9+
Arguments:
10+
11+
- **options** `Dispatch.DispatchOptions & RetryOptions` (required) - It is an intersection of `Dispatcher.DispatchOptions` and `RetryOptions`.
12+
- **retryHandlers** `RetryHandlers` (required) - Object containing the `dispatch` to be used on every retry, and `handler` for handling the `dispatch` lifecycle.
13+
14+
Returns: `retryHandler`
15+
16+
### Parameter: `Dispatch.DispatchOptions & RetryOptions`
17+
18+
Extends: [`Dispatch.DispatchOptions`](Dispatcher.md#parameter-dispatchoptions).
19+
20+
#### `RetryOptions`
21+
22+
- **retry** `(err: Error, context: RetryContext, callback: (err?: Error | null) => void) => void` (optional) - Function to be called after every retry. It should pass error if no more retries should be performed.
23+
- **maxRetries** `number` (optional) - Maximum number of retries. Default: `5`
24+
- **maxTimeout** `number` (optional) - Maximum number of milliseconds to wait before retrying. Default: `30000` (30 seconds)
25+
- **minTimeout** `number` (optional) - Minimum number of milliseconds to wait before retrying. Default: `500` (half a second)
26+
- **timeoutFactor** `number` (optional) - Factor to multiply the timeout by for each retry attempt. Default: `2`
27+
- **retryAfter** `boolean` (optional) - It enables automatic retry after the `Retry-After` header is received. Default: `true`
28+
-
29+
- **methods** `string[]` (optional) - Array of HTTP methods to retry. Default: `['GET', 'PUT', 'HEAD', 'OPTIONS', 'DELETE']`
30+
- **statusCodes** `number[]` (optional) - Array of HTTP status codes to retry. Default: `[429, 500, 502, 503, 504]`
31+
- **errorCodes** `string[]` (optional) - Array of Error codes to retry. Default: `['ECONNRESET', 'ECONNREFUSED', 'ENOTFOUND', 'ENETDOWN','ENETUNREACH', 'EHOSTDOWN',
32+
33+
**`RetryContext`**
34+
35+
- `state`: `RetryState` - Current retry state. It can be mutated.
36+
- `opts`: `Dispatch.DispatchOptions & RetryOptions` - Options passed to the retry handler.
37+
38+
### Parameter `RetryHandlers`
39+
40+
- **dispatch** `(options: Dispatch.DispatchOptions, handlers: Dispatch.DispatchHandlers) => Promise<Dispatch.DispatchResponse>` (required) - Dispatch function to be called after every retry.
41+
- **handler** Extends [`Dispatch.DispatchHandlers`](Dispatcher.md#dispatcherdispatchoptions-handler) (required) - Handler function to be called after the request is successful or the retries are exhausted.
42+
43+
Examples:
44+
45+
```js
46+
const client = new Client(`http://localhost:${server.address().port}`);
47+
const chunks = [];
48+
const handler = new RetryHandler(
49+
{
50+
...dispatchOptions,
51+
retryOptions: {
52+
// custom retry function
53+
retry: function (err, state, callback) {
54+
counter++;
55+
56+
if (err.code && err.code === "UND_ERR_DESTROYED") {
57+
callback(err);
58+
return;
59+
}
60+
61+
if (err.statusCode === 206) {
62+
callback(err);
63+
return;
64+
}
65+
66+
setTimeout(() => callback(null), 1000);
67+
},
68+
},
69+
},
70+
{
71+
dispatch: (...args) => {
72+
return client.dispatch(...args);
73+
},
74+
handler: {
75+
onConnect() {},
76+
onBodySent() {},
77+
onHeaders(status, _rawHeaders, resume, _statusMessage) {
78+
// do something with headers
79+
},
80+
onData(chunk) {
81+
chunks.push(chunk);
82+
return true;
83+
},
84+
onComplete() {},
85+
onError() {
86+
// handle error properly
87+
},
88+
},
89+
}
90+
);
91+
```
92+
93+
#### Example - Basic RetryHandler with defaults
94+
95+
```js
96+
const client = new Client(`http://localhost:${server.address().port}`);
97+
const handler = new RetryHandler(dispatchOptions, {
98+
dispatch: client.dispatch.bind(client),
99+
handler: {
100+
onConnect() {},
101+
onBodySent() {},
102+
onHeaders(status, _rawHeaders, resume, _statusMessage) {},
103+
onData(chunk) {},
104+
onComplete() {},
105+
onError(err) {},
106+
},
107+
});
108+
```

deps/undici/src/index-fetch.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
const fetchImpl = require('./lib/fetch').fetch
44

5-
module.exports.fetch = async function fetch (resource) {
6-
try {
7-
return await fetchImpl(...arguments)
8-
} catch (err) {
5+
module.exports.fetch = function fetch (resource, init = undefined) {
6+
return fetchImpl(resource, init).catch((err) => {
97
Error.captureStackTrace(err, this)
108
throw err
11-
}
9+
})
1210
}
1311
module.exports.FormData = require('./lib/fetch/formdata').FormData
1412
module.exports.Headers = require('./lib/fetch/headers').Headers
1513
module.exports.Response = require('./lib/fetch/response').Response
1614
module.exports.Request = require('./lib/fetch/request').Request
15+
module.exports.WebSocket = require('./lib/websocket/websocket').WebSocket

deps/undici/src/index.d.ts

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,3 @@
1-
import Dispatcher from'./types/dispatcher'
2-
import { setGlobalDispatcher, getGlobalDispatcher } from './types/global-dispatcher'
3-
import { setGlobalOrigin, getGlobalOrigin } from './types/global-origin'
4-
import Pool from'./types/pool'
5-
import { RedirectHandler, DecoratorHandler } from './types/handlers'
6-
7-
import BalancedPool from './types/balanced-pool'
8-
import Client from'./types/client'
9-
import buildConnector from'./types/connector'
10-
import errors from'./types/errors'
11-
import Agent from'./types/agent'
12-
import MockClient from'./types/mock-client'
13-
import MockPool from'./types/mock-pool'
14-
import MockAgent from'./types/mock-agent'
15-
import mockErrors from'./types/mock-errors'
16-
import ProxyAgent from'./types/proxy-agent'
17-
import { request, pipeline, stream, connect, upgrade } from './types/api'
18-
19-
export * from './types/cookies'
20-
export * from './types/fetch'
21-
export * from './types/file'
22-
export * from './types/filereader'
23-
export * from './types/formdata'
24-
export * from './types/diagnostics-channel'
25-
export * from './types/websocket'
26-
export * from './types/content-type'
27-
export * from './types/cache'
28-
export { Interceptable } from './types/mock-interceptor'
29-
30-
export { Dispatcher, BalancedPool, Pool, Client, buildConnector, errors, Agent, request, stream, pipeline, connect, upgrade, setGlobalDispatcher, getGlobalDispatcher, setGlobalOrigin, getGlobalOrigin, MockClient, MockPool, MockAgent, mockErrors, ProxyAgent, RedirectHandler, DecoratorHandler }
1+
export * from './types/index'
2+
import Undici from './types/index'
313
export default Undici
32-
33-
declare namespace Undici {
34-
var Dispatcher: typeof import('./types/dispatcher').default
35-
var Pool: typeof import('./types/pool').default;
36-
var RedirectHandler: typeof import ('./types/handlers').RedirectHandler
37-
var DecoratorHandler: typeof import ('./types/handlers').DecoratorHandler
38-
var createRedirectInterceptor: typeof import ('./types/interceptors').createRedirectInterceptor
39-
var BalancedPool: typeof import('./types/balanced-pool').default;
40-
var Client: typeof import('./types/client').default;
41-
var buildConnector: typeof import('./types/connector').default;
42-
var errors: typeof import('./types/errors').default;
43-
var Agent: typeof import('./types/agent').default;
44-
var setGlobalDispatcher: typeof import('./types/global-dispatcher').setGlobalDispatcher;
45-
var getGlobalDispatcher: typeof import('./types/global-dispatcher').getGlobalDispatcher;
46-
var request: typeof import('./types/api').request;
47-
var stream: typeof import('./types/api').stream;
48-
var pipeline: typeof import('./types/api').pipeline;
49-
var connect: typeof import('./types/api').connect;
50-
var upgrade: typeof import('./types/api').upgrade;
51-
var MockClient: typeof import('./types/mock-client').default;
52-
var MockPool: typeof import('./types/mock-pool').default;
53-
var MockAgent: typeof import('./types/mock-agent').default;
54-
var mockErrors: typeof import('./types/mock-errors').default;
55-
var fetch: typeof import('./types/fetch').fetch;
56-
var caches: typeof import('./types/cache').caches;
57-
}

0 commit comments

Comments
 (0)