Skip to content

Commit

Permalink
deps: update undici to 6.10.2
Browse files Browse the repository at this point in the history
PR-URL: #52227
Reviewed-By: Matthew Aitken <[email protected]>
Reviewed-By: Filip Skokan <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Luigi Pinca <[email protected]>
Reviewed-By: Mohammed Keyvanzadeh <[email protected]>
  • Loading branch information
nodejs-github-bot authored Mar 29, 2024
1 parent 29de7f8 commit 511be6c
Show file tree
Hide file tree
Showing 145 changed files with 14,521 additions and 23,006 deletions.
76 changes: 49 additions & 27 deletions deps/undici/src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,24 +17,42 @@ npm i undici

## Benchmarks

The benchmark is a simple `hello world` [example](benchmarks/benchmark.js) using a
The benchmark is a simple getting data [example](https://github.com/nodejs/undici/blob/main/benchmarks/benchmark.js) using a
50 TCP connections with a pipelining depth of 10 running on Node 20.10.0.

```
β”‚ Tests β”‚ Samples β”‚ Result β”‚ Tolerance β”‚ Difference with slowest β”‚
|─────────────────────|─────────|─────────────────|───────────|─────────────────────────|
β”‚ got β”‚ 45 β”‚ 1661.71 req/sec β”‚ Β± 2.93 % β”‚ - β”‚
β”‚ node-fetch β”‚ 20 β”‚ 2164.81 req/sec β”‚ Β± 2.63 % β”‚ + 30.28 % β”‚
β”‚ undici - fetch β”‚ 35 β”‚ 2274.27 req/sec β”‚ Β± 2.70 % β”‚ + 36.86 % β”‚
β”‚ http - no keepalive β”‚ 15 β”‚ 2376.04 req/sec β”‚ Β± 2.99 % β”‚ + 42.99 % β”‚
β”‚ axios β”‚ 25 β”‚ 2612.93 req/sec β”‚ Β± 2.89 % β”‚ + 57.24 % β”‚
β”‚ request β”‚ 40 β”‚ 2712.19 req/sec β”‚ Β± 2.92 % β”‚ + 63.22 % β”‚
β”‚ http - keepalive β”‚ 45 β”‚ 4393.25 req/sec β”‚ Β± 2.86 % β”‚ + 164.38 % β”‚
β”‚ undici - pipeline β”‚ 45 β”‚ 5484.69 req/sec β”‚ Β± 2.87 % β”‚ + 230.06 % β”‚
β”‚ undici - request β”‚ 55 β”‚ 7773.98 req/sec β”‚ Β± 2.93 % β”‚ + 367.83 % β”‚
β”‚ undici - stream β”‚ 70 β”‚ 8425.96 req/sec β”‚ Β± 2.91 % β”‚ + 407.07 % β”‚
β”‚ undici - dispatch β”‚ 50 β”‚ 9488.99 req/sec β”‚ Β± 2.85 % β”‚ + 471.04 % β”‚
```
| _Tests_ | _Samples_ | _Result_ | _Tolerance_ | _Difference with slowest_ |
| :-----------------: | :-------: | :--------------: | :---------: | :-----------------------: |
| undici - fetch | 30 | 3704.43 req/sec | Β± 2.95 % | - |
| http - no keepalive | 20 | 4275.30 req/sec | Β± 2.60 % | + 15.41 % |
| node-fetch | 10 | 4759.42 req/sec | Β± 0.87 % | + 28.48 % |
| request | 40 | 4803.37 req/sec | Β± 2.77 % | + 29.67 % |
| axios | 45 | 4951.97 req/sec | Β± 2.88 % | + 33.68 % |
| got | 10 | 5969.67 req/sec | Β± 2.64 % | + 61.15 % |
| superagent | 10 | 9471.48 req/sec | Β± 1.50 % | + 155.68 % |
| http - keepalive | 25 | 10327.49 req/sec | Β± 2.95 % | + 178.79 % |
| undici - pipeline | 10 | 15053.41 req/sec | Β± 1.63 % | + 306.36 % |
| undici - request | 10 | 19264.24 req/sec | Β± 1.74 % | + 420.03 % |
| undici - stream | 15 | 20317.29 req/sec | Β± 2.13 % | + 448.46 % |
| undici - dispatch | 10 | 24883.28 req/sec | Β± 1.54 % | + 571.72 % |

The benchmark is a simple sending data [example](https://github.com/nodejs/undici/blob/main/benchmarks/post-benchmark.js) using a
50 TCP connections with a pipelining depth of 10 running on Node 20.10.0.

| _Tests_ | _Samples_ | _Result_ | _Tolerance_ | _Difference with slowest_ |
| :-----------------: | :-------: | :-------------: | :---------: | :-----------------------: |
| undici - fetch | 20 | 1968.42 req/sec | Β± 2.63 % | - |
| http - no keepalive | 25 | 2330.30 req/sec | Β± 2.99 % | + 18.38 % |
| node-fetch | 20 | 2485.36 req/sec | Β± 2.70 % | + 26.26 % |
| got | 15 | 2787.68 req/sec | Β± 2.56 % | + 41.62 % |
| request | 30 | 2805.10 req/sec | Β± 2.59 % | + 42.50 % |
| axios | 10 | 3040.45 req/sec | Β± 1.72 % | + 54.46 % |
| superagent | 20 | 3358.29 req/sec | Β± 2.51 % | + 70.61 % |
| http - keepalive | 20 | 3477.94 req/sec | Β± 2.51 % | + 76.69 % |
| undici - pipeline | 25 | 3812.61 req/sec | Β± 2.80 % | + 93.69 % |
| undici - request | 10 | 6067.00 req/sec | Β± 0.94 % | + 208.22 % |
| undici - stream | 10 | 6391.61 req/sec | Β± 1.98 % | + 224.71 % |
| undici - dispatch | 10 | 6397.00 req/sec | Β± 1.48 % | + 224.98 % |


## Quick Start

Expand All @@ -60,10 +78,14 @@ console.log('trailers', trailers)

The `body` mixins are the most common way to format the request/response body. Mixins include:

- [`.formData()`](https://fetch.spec.whatwg.org/#dom-body-formdata)
- [`.arrayBuffer()`](https://fetch.spec.whatwg.org/#dom-body-arraybuffer)
- [`.blob()`](https://fetch.spec.whatwg.org/#dom-body-blob)
- [`.json()`](https://fetch.spec.whatwg.org/#dom-body-json)
- [`.text()`](https://fetch.spec.whatwg.org/#dom-body-text)

> [!NOTE]
> The body returned from `undici.request` does not implement `.formData()`.
Example usage:

```js
Expand Down Expand Up @@ -123,14 +145,14 @@ Returns a promise with the result of the `Dispatcher.stream` method.

Calls `options.dispatcher.stream(options, factory)`.

See [Dispatcher.stream](docs/api/Dispatcher.md#dispatcherstreamoptions-factory-callback) for more details.
See [Dispatcher.stream](./docs/api/Dispatcher.md#dispatcherstreamoptions-factory-callback) for more details.

### `undici.pipeline([url, options, ]handler): Duplex`

Arguments:

* **url** `string | URL | UrlObject`
* **options** [`PipelineOptions`](docs/api/Dispatcher.md#parameter-pipelineoptions)
* **options** [`PipelineOptions`](./docs/api/Dispatcher.md#parameter-pipelineoptions)
* **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcher)
* **method** `String` - Default: `PUT` if `options.body`, otherwise `GET`
* **maxRedirections** `Integer` - Default: `0`
Expand All @@ -140,7 +162,7 @@ Returns: `stream.Duplex`

Calls `options.dispatch.pipeline(options, handler)`.

See [Dispatcher.pipeline](docs/api/Dispatcher.md#dispatcherpipelineoptions-handler) for more details.
See [Dispatcher.pipeline](./docs/api/Dispatcher.md#dispatcherpipelineoptions-handler) for more details.

### `undici.connect([url, options]): Promise`

Expand All @@ -149,7 +171,7 @@ Starts two-way communications with the requested resource using [HTTP CONNECT](h
Arguments:

* **url** `string | URL | UrlObject`
* **options** [`ConnectOptions`](docs/api/Dispatcher.md#parameter-connectoptions)
* **options** [`ConnectOptions`](./docs/api/Dispatcher.md#parameter-connectoptions)
* **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcher)
* **maxRedirections** `Integer` - Default: `0`
* **callback** `(err: Error | null, data: ConnectData | null) => void` (optional)
Expand All @@ -158,7 +180,7 @@ Returns a promise with the result of the `Dispatcher.connect` method.

Calls `options.dispatch.connect(options)`.

See [Dispatcher.connect](docs/api/Dispatcher.md#dispatcherconnectoptions-callback) for more details.
See [Dispatcher.connect](./docs/api/Dispatcher.md#dispatcherconnectoptions-callback) for more details.

### `undici.fetch(input[, init]): Promise`

Expand Down Expand Up @@ -226,7 +248,7 @@ await fetch('https://example.com', { body: data, method: 'POST', duplex: 'half'

- half

In this implementation of fetch, `request.duplex` must be set if `request.body` is `ReadableStream` or `Async Iterables`. And fetch requests are currently always be full duplex. More detail refer to [Fetch Standard.](https://fetch.spec.whatwg.org/#dom-requestinit-duplex)
In this implementation of fetch, `request.duplex` must be set if `request.body` is `ReadableStream` or `Async Iterables`, however, fetch requests are currently always full duplex. For more detail refer to the [Fetch Standard.](https://fetch.spec.whatwg.org/#dom-requestinit-duplex).

#### `response.body`

Expand Down Expand Up @@ -297,7 +319,7 @@ Upgrade to a different protocol. See [MDN - HTTP - Protocol upgrade mechanism](h
Arguments:

* **url** `string | URL | UrlObject`
* **options** [`UpgradeOptions`](docs/api/Dispatcher.md#parameter-upgradeoptions)
* **options** [`UpgradeOptions`](./docs/api/Dispatcher.md#parameter-upgradeoptions)
* **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcher)
* **maxRedirections** `Integer` - Default: `0`
* **callback** `(error: Error | null, data: UpgradeData) => void` (optional)
Expand All @@ -306,7 +328,7 @@ Returns a promise with the result of the `Dispatcher.upgrade` method.

Calls `options.dispatcher.upgrade(options)`.

See [Dispatcher.upgrade](docs/api/Dispatcher.md#dispatcherupgradeoptions-callback) for more details.
See [Dispatcher.upgrade](./docs/api/Dispatcher.md#dispatcherupgradeoptions-callback) for more details.

### `undici.setGlobalDispatcher(dispatcher)`

Expand Down Expand Up @@ -400,9 +422,9 @@ Refs: https://fetch.spec.whatwg.org/#atomic-http-redirect-handling

If you experience problem when connecting to a remote server that is resolved by your DNS servers to a IPv6 (AAAA record)
first, there are chances that your local router or ISP might have problem connecting to IPv6 networks. In that case
undici will throw an error with code `UND_ERR_CONNECT_TIMEOUT`.
undici will throw an error with code `UND_ERR_CONNECT_TIMEOUT`.

If the target server resolves to both a IPv6 and IPv4 (A records) address and you are using a compatible Node version
If the target server resolves to both a IPv6 and IPv4 (A records) address and you are using a compatible Node version
(18.3.0 and above), you can fix the problem by providing the `autoSelectFamily` option (support by both `undici.request`
and `undici.Agent`) which will enable the family autoselection algorithm when establishing the connection.

Expand Down
27 changes: 0 additions & 27 deletions deps/undici/src/docs/api/Fetch.md

This file was deleted.

Binary file removed deps/undici/src/docs/assets/lifecycle-diagram.png
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ Returns: `Client`
* **pipelining** `number | null` (optional) - Default: `1` - 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). Carefully consider your workload and environment before enabling concurrent requests as pipelining may reduce performance if used incorrectly. Pipelining is sensitive to network stack settings as well as head of line blocking caused by e.g. long running requests. Set to `0` to disable keep-alive connections.
* **connect** `ConnectOptions | Function | null` (optional) - Default: `null`.
* **strictContentLength** `Boolean` (optional) - Default: `true` - Whether to treat request content length mismatches as errors. If true, an error is thrown when the request content-length header doesn't match the length of the request body.
* **interceptors** `{ Client: DispatchInterceptor[] }` - Default: `[RedirectInterceptor]` - A list of interceptors that are applied to the dispatch method. Additional logic can be applied (such as, but not limited to: 302 status code handling, authentication, cookies, compression and caching). Note that the behavior of interceptors is Experimental and might change at any given time.
<!-- TODO: Remove once we drop its support -->
* **interceptors** `{ Client: DispatchInterceptor[] }` - Default: `[RedirectInterceptor]` - A list of interceptors that are applied to the dispatch method. Additional logic can be applied (such as, but not limited to: 302 status code handling, authentication, cookies, compression and caching). Note that the behavior of interceptors is Experimental and might change at any given time. **Note: this is deprecated in favor of [Dispatcher#compose](./Dispatcher.md#dispatcher). Support will be droped in next major.**
* **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.
* **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.
* **allowH2**: `boolean` - Default: `false`. Enables support for H2 if the server has assigned bigger priority to it through ALPN negotiation.
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ diagnosticsChannel.channel('undici:request:create').subscribe(({ request }) => {
console.log('completed', request.completed)
console.log('method', request.method)
console.log('path', request.path)
console.log('headers') // raw text, e.g: 'bar: bar\r\n'
console.log('headers') // array of strings, e.g: ['foo', 'bar']
request.addHeader('hello', 'world')
console.log('headers', request.headers) // e.g. 'bar: bar\r\nhello: world\r\n'
console.log('headers', request.headers) // e.g. ['foo', 'bar', 'hello', 'world']
})
```

Expand Down
Loading

0 comments on commit 511be6c

Please sign in to comment.