@@ -21,28 +21,65 @@ npm i undici |
21 | 21 |
|
22 | 22 | ## Benchmarks |
23 | 23 |
|
24 | | -The benchmark is a simple getting data [example](https://github.com/nodejs/undici/blob/main/benchmarks/benchmark.js) using a |
25 | | -50 TCP connections with a pipelining depth of 10 running on Node 22.11.0. |
| 24 | +The benchmark is a simple getting data [example](https://github.com/nodejs/undici/blob/main/benchmarks/benchmark.js) using |
| 25 | +50 TCP connections with a pipelining depth of 10 running on Node 24.14.1. |
| 26 | + |
| 27 | +### HTTP/1.1 |
26 | 28 |
|
27 | 29 | ``` |
28 | 30 | ┌────────────────────────┬─────────┬────────────────────┬────────────┬─────────────────────────┐ |
29 | 31 | │ Tests │ Samples │ Result │ Tolerance │ Difference with slowest │ |
30 | 32 | ├────────────────────────┼─────────┼────────────────────┼────────────┼─────────────────────────┤ |
31 | | -│ 'axios' │ 15 │ '5708.26 req/sec' │ '± 2.91 %' │ '-' │ |
32 | | -│ 'http - no keepalive' │ 10 │ '5809.80 req/sec' │ '± 2.30 %' │ '+ 1.78 %' │ |
33 | | -│ 'request' │ 30 │ '5828.80 req/sec' │ '± 2.91 %' │ '+ 2.11 %' │ |
34 | | -│ 'undici - fetch' │ 40 │ '5903.78 req/sec' │ '± 2.87 %' │ '+ 3.43 %' │ |
35 | | -│ 'node-fetch' │ 10 │ '5945.40 req/sec' │ '± 2.13 %' │ '+ 4.15 %' │ |
36 | | -│ 'got' │ 35 │ '6511.45 req/sec' │ '± 2.84 %' │ '+ 14.07 %' │ |
37 | | -│ 'http - keepalive' │ 65 │ '9193.24 req/sec' │ '± 2.92 %' │ '+ 61.05 %' │ |
38 | | -│ 'superagent' │ 35 │ '9339.43 req/sec' │ '± 2.95 %' │ '+ 63.61 %' │ |
39 | | -│ 'undici - pipeline' │ 50 │ '13364.62 req/sec' │ '± 2.93 %' │ '+ 134.13 %' │ |
40 | | -│ 'undici - stream' │ 95 │ '18245.36 req/sec' │ '± 2.99 %' │ '+ 219.63 %' │ |
41 | | -│ 'undici - request' │ 50 │ '18340.17 req/sec' │ '± 2.84 %' │ '+ 221.29 %' │ |
42 | | -│ 'undici - dispatch' │ 40 │ '22234.42 req/sec' │ '± 2.94 %' │ '+ 289.51 %' │ |
| 33 | +│ 'node-fetch' │ 50 │ '4711.86 req/sec' │ '± 2.92 %' │ '-' │ |
| 34 | +│ 'undici - fetch' │ 75 │ '5438.50 req/sec' │ '± 2.97 %' │ '+ 15.42 %' │ |
| 35 | +│ 'axios' │ 45 │ '5448.08 req/sec' │ '± 2.98 %' │ '+ 15.62 %' │ |
| 36 | +│ 'request' │ 65 │ '5809.63 req/sec' │ '± 2.90 %' │ '+ 23.30 %' │ |
| 37 | +│ 'http - no keepalive' │ 35 │ '5910.77 req/sec' │ '± 2.87 %' │ '+ 25.44 %' │ |
| 38 | +│ 'got' │ 50 │ '6047.80 req/sec' │ '± 2.91 %' │ '+ 28.35 %' │ |
| 39 | +│ 'superagent' │ 60 │ '7534.53 req/sec' │ '± 2.97 %' │ '+ 59.91 %' │ |
| 40 | +│ 'http - keepalive' │ 75 │ '9343.41 req/sec' │ '± 2.90 %' │ '+ 98.30 %' │ |
| 41 | +│ 'undici - pipeline' │ 65 │ '13470.70 req/sec' │ '± 2.93 %' │ '+ 185.89 %' │ |
| 42 | +│ 'undici - request' │ 80 │ '16850.87 req/sec' │ '± 2.93 %' │ '+ 257.63 %' │ |
| 43 | +│ 'undici - stream' │ 101 │ '18488.56 req/sec' │ '± 3.81 %' │ '+ 292.38 %' │ |
| 44 | +│ 'undici - dispatch' │ 101 │ '20786.44 req/sec' │ '± 3.08 %' │ '+ 341.15 %' │ |
43 | 45 | └────────────────────────┴─────────┴────────────────────┴────────────┴─────────────────────────┘ |
44 | 46 | ``` |
45 | 47 |
|
| 48 | +### HTTP/1.1 over HTTPS |
| 49 | + |
| 50 | +Using [benchmark-https.js](https://github.com/nodejs/undici/blob/main/benchmarks/benchmark-https.js) against an h1-over-TLS server (50 connections, pipelining depth 10, Node 24.14.1). |
| 51 | + |
| 52 | +``` |
| 53 | +┌────────────────────────┬─────────┬───────────────────┬────────────┬─────────────────────────┐ |
| 54 | +│ Tests │ Samples │ Result │ Tolerance │ Difference with slowest │ |
| 55 | +├────────────────────────┼─────────┼───────────────────┼────────────┼─────────────────────────┤ |
| 56 | +│ 'https - no keepalive'│ 10 │ '1358.40 req/sec' │ '± 1.99 %' │ '-' │ |
| 57 | +│ 'undici - fetch' │ 30 │ '3721.76 req/sec' │ '± 2.97 %' │ '+ 173.98 %' │ |
| 58 | +│ 'https - keepalive' │ 35 │ '5633.91 req/sec' │ '± 2.84 %' │ '+ 314.75 %' │ |
| 59 | +│ 'undici - pipeline' │ 15 │ '6254.05 req/sec' │ '± 2.80 %' │ '+ 360.40 %' │ |
| 60 | +│ 'undici - request' │ 25 │ '6669.80 req/sec' │ '± 2.73 %' │ '+ 391.01 %' │ |
| 61 | +│ 'undici - stream' │ 25 │ '7019.04 req/sec' │ '± 2.77 %' │ '+ 416.71 %' │ |
| 62 | +│ 'undici - dispatch' │ 20 │ '7361.85 req/sec' │ '± 2.90 %' │ '+ 441.95 %' │ |
| 63 | +└────────────────────────┴─────────┴───────────────────┴────────────┴─────────────────────────┘ |
| 64 | +``` |
| 65 | + |
| 66 | +### HTTP/2 |
| 67 | + |
| 68 | +Using [benchmark-http2.js](https://github.com/nodejs/undici/blob/main/benchmarks/benchmark-http2.js) against an h2 server (50 connections, pipelining depth 10, Node 24.14.1). |
| 69 | + |
| 70 | +``` |
| 71 | +┌────────────────────────┬─────────┬───────────────────┬────────────┬─────────────────────────┐ |
| 72 | +│ Tests │ Samples │ Result │ Tolerance │ Difference with slowest │ |
| 73 | +├────────────────────────┼─────────┼───────────────────┼────────────┼─────────────────────────┤ |
| 74 | +│ 'undici - fetch' │ 45 │ '3499.03 req/sec' │ '± 2.93 %' │ '-' │ |
| 75 | +│ 'native - http2' │ 25 │ '4904.58 req/sec' │ '± 2.81 %' │ '+ 40.17 %' │ |
| 76 | +│ 'undici - pipeline' │ 60 │ '5836.82 req/sec' │ '± 2.99 %' │ '+ 66.81 %' │ |
| 77 | +│ 'undici - request' │ 65 │ '6831.25 req/sec' │ '± 2.83 %' │ '+ 95.23 %' │ |
| 78 | +│ 'undici - stream' │ 55 │ '6874.30 req/sec' │ '± 2.91 %' │ '+ 96.46 %' │ |
| 79 | +│ 'undici - dispatch' │ 55 │ '7791.23 req/sec' │ '± 2.96 %' │ '+ 122.67 %' │ |
| 80 | +└────────────────────────┴─────────┴───────────────────┴────────────┴─────────────────────────┘ |
| 81 | +``` |
| 82 | + |
46 | 83 | ## Undici vs. Fetch |
47 | 84 |
|
48 | 85 | ### Overview |
@@ -340,6 +377,9 @@ The `body` mixins are the most common way to format the request/response body. M |
340 | 377 | > [!NOTE] |
341 | 378 | > The body returned from `undici.request` does not implement `.formData()`. |
342 | 379 |
|
| 380 | +> [!WARNING] |
| 381 | +> Calling `body.formData()` on a fetch response causes undici to buffer and parse the entire body. Since this is dictated by the spec, `body.formData()` must only be called on responses from trusted servers. |
| 382 | +
|
343 | 383 | Example usage: |
344 | 384 |
|
345 | 385 | ```js |
@@ -740,10 +780,11 @@ and `undici.Agent`) which will enable the family autoselection algorithm when es |
740 | 780 | Undici aligns with the Node.js LTS schedule. The following table shows the supported versions: |
741 | 781 |
|
742 | 782 | | Undici Version | Bundled in Node.js | Node.js Versions Supported | End of Life | |
743 | | -|----------------|-------------------|----------------------------|-------------| |
744 | | -| 5.x | 18.x | ≥14.0 (tested: 14, 16, 18) | 2024-04-30 | |
745 | | -| 6.x | 20.x, 22.x | ≥18.17 (tested: 18, 20, 21, 22) | 2026-04-30 | |
746 | | -| 7.x | 24.x | ≥20.18.1 (tested: 20, 22, 24) | 2027-04-30 | |
| 783 | +|----------------|--------------------|----------------------------|-------------| |
| 784 | +| 5.x | 18.x | ≥14.0 (tested: 14, 16, 18) | 2024-04-30 | |
| 785 | +| 6.x | 20.x, 22.x | ≥18.17 (tested: 18, 20, 21, 22) | 2027-04-30 | |
| 786 | +| 7.x | 24.x | ≥20.18.1 (tested: 20, 22, 24) | 2028-04-30 | |
| 787 | +| 8.x | 26.x | ≥22.19.0 (tested: 22, 24, 26) | 2029-04-30 | |
747 | 788 |
|
748 | 789 | ## License |
749 | 790 |
|
|