Skip to content

Commit 6c03beb

Browse files
deps: update undici to 7.1.0
PR-URL: #56179 Reviewed-By: Rafael Gonzaga <[email protected]> Reviewed-By: Michaël Zasso <[email protected]>
1 parent 4831423 commit 6c03beb

File tree

14 files changed

+398
-291
lines changed

14 files changed

+398
-291
lines changed

deps/undici/src/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,8 @@ and `undici.Agent`) which will enable the family autoselection algorithm when es
434434
* [__Matthew Aitken__](https://github.com/KhafraDev), <https://www.npmjs.com/~khaf>
435435
* [__Robert Nagy__](https://github.com/ronag), <https://www.npmjs.com/~ronag>
436436
* [__Szymon Marczak__](https://github.com/szmarczak), <https://www.npmjs.com/~szmarczak>
437+
438+
## Past Collaborators
437439
* [__Tomas Della Vedova__](https://github.com/delvedor), <https://www.npmjs.com/~delvedor>
438440

439441
### Releasers

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ Returns: `Client`
1717

1818
### Parameter: `ClientOptions`
1919

20-
> ⚠️ Warning: The `H2` support is experimental.
21-
2220
* **bodyTimeout** `number | null` (optional) - Default: `300e3` - 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. Please note the `timeout` will be reset if you keep writing data to the socket everytime.
2321
* **headersTimeout** `number | null` (optional) - Default: `300e3` - 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.
2422
* **keepAliveMaxTimeout** `number | null` (optional) - Default: `600e3` - The maximum allowed `keepAliveTimeout`, in milliseconds, when overridden by *keep-alive* hints from the server. Defaults to 10 minutes.
@@ -34,6 +32,17 @@ Returns: `Client`
3432
* **allowH2**: `boolean` - Default: `false`. Enables support for H2 if the server has assigned bigger priority to it through ALPN negotiation.
3533
* **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.
3634

35+
> **Notes about HTTP/2**
36+
> - It only works under TLS connections. h2c is not supported.
37+
> - The server must support HTTP/2 and choose it as the protocol during the ALPN negotiation.
38+
> - The server must not have a bigger priority for HTTP/1.1 than HTTP/2.
39+
> - Pseudo headers are automatically attached to the request. If you try to set them, they will be overwritten.
40+
> - The `:path` header is automatically set to the request path.
41+
> - The `:method` header is automatically set to the request method.
42+
> - The `:scheme` header is automatically set to the request scheme.
43+
> - The `:authority` header is automatically set to the request `host[:port]`.
44+
> - `PUSH` frames are yet not supported.
45+
3746
#### Parameter: `ConnectOptions`
3847

3948
Every Tls option, see [here](https://nodejs.org/api/tls.html#tls_tls_connect_options_callback).

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

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,91 @@ Implements [`Agent.dispatch(options, handlers)`](/docs/docs/api/Agent.md#paramet
128128
### `ProxyAgent.request(options[, callback])`
129129

130130
See [`Dispatcher.request(options [, callback])`](/docs/docs/api/Dispatcher.md#dispatcherrequestoptions-callback).
131+
132+
133+
#### Example - ProxyAgent with Fetch
134+
135+
This example demonstrates how to use `fetch` with a proxy via `ProxyAgent`. It is particularly useful for scenarios requiring proxy tunneling.
136+
137+
```javascript
138+
import { ProxyAgent, fetch } from 'undici';
139+
140+
// Define the ProxyAgent
141+
const proxyAgent = new ProxyAgent('http://localhost:8000');
142+
143+
// Make a GET request through the proxy
144+
const response = await fetch('http://localhost:3000/foo', {
145+
dispatcher: proxyAgent,
146+
method: 'GET',
147+
});
148+
149+
console.log('Response status:', response.status);
150+
console.log('Response data:', await response.text());
151+
```
152+
153+
---
154+
155+
#### Example - ProxyAgent with a Custom Proxy Server
156+
157+
This example shows how to create a custom proxy server and use it with `ProxyAgent`.
158+
159+
```javascript
160+
import * as http from 'node:http';
161+
import { createProxy } from 'proxy';
162+
import { ProxyAgent, fetch } from 'undici';
163+
164+
// Create a proxy server
165+
const proxyServer = createProxy(http.createServer());
166+
proxyServer.listen(8000, () => {
167+
console.log('Proxy server running on port 8000');
168+
});
169+
170+
// Define and use the ProxyAgent
171+
const proxyAgent = new ProxyAgent('http://localhost:8000');
172+
173+
const response = await fetch('http://example.com', {
174+
dispatcher: proxyAgent,
175+
method: 'GET',
176+
});
177+
178+
console.log('Response status:', response.status);
179+
console.log('Response data:', await response.text());
180+
```
181+
182+
---
183+
184+
#### Example - ProxyAgent with HTTPS Tunneling
185+
186+
This example demonstrates how to perform HTTPS tunneling using a proxy.
187+
188+
```javascript
189+
import { ProxyAgent, fetch } from 'undici';
190+
191+
// Define a ProxyAgent for HTTPS proxy
192+
const proxyAgent = new ProxyAgent('https://secure.proxy.server');
193+
194+
// Make a request to an HTTPS endpoint via the proxy
195+
const response = await fetch('https://secure.endpoint.com/api/data', {
196+
dispatcher: proxyAgent,
197+
method: 'GET',
198+
});
199+
200+
console.log('Response status:', response.status);
201+
console.log('Response data:', await response.json());
202+
```
203+
204+
#### Example - ProxyAgent as a Global Dispatcher
205+
206+
`ProxyAgent` can be configured as a global dispatcher, making it available for all requests without explicitly passing it. This simplifies code and is useful when a single proxy configuration applies to all requests.
207+
208+
```javascript
209+
import { ProxyAgent, setGlobalDispatcher, fetch } from 'undici';
210+
211+
// Define and configure the ProxyAgent
212+
const proxyAgent = new ProxyAgent('http://localhost:8000');
213+
setGlobalDispatcher(proxyAgent);
214+
215+
// Make requests without specifying the dispatcher
216+
const response = await fetch('http://example.com');
217+
console.log('Response status:', response.status);
218+
console.log('Response data:', await response.text());

deps/undici/src/index.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,10 @@ try {
5353
const SqliteCacheStore = require('./lib/cache/sqlite-cache-store')
5454
module.exports.cacheStores.SqliteCacheStore = SqliteCacheStore
5555
} catch (err) {
56-
if (err.code !== 'ERR_UNKNOWN_BUILTIN_MODULE') {
57-
throw err
58-
}
56+
// Most likely node:sqlite was not present, since SqliteCacheStore is
57+
// optional, don't throw. Don't check specific error codes here because while
58+
// ERR_UNKNOWN_BUILTIN_MODULE is expected, users have seen other codes like
59+
// MODULE_NOT_FOUND
5960
}
6061

6162
module.exports.buildConnector = buildConnector

deps/undici/src/lib/dispatcher/client-h2.js

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ const kOpenStreams = Symbol('open streams')
3535

3636
let extractBody
3737

38-
// Experimental
39-
let h2ExperimentalWarned = false
40-
4138
/** @type {import('http2')} */
4239
let http2
4340
try {
@@ -82,13 +79,6 @@ function parseH2Headers (headers) {
8279
async function connectH2 (client, socket) {
8380
client[kSocket] = socket
8481

85-
if (!h2ExperimentalWarned) {
86-
h2ExperimentalWarned = true
87-
process.emitWarning('H2 support is experimental, expect them to change at any time.', {
88-
code: 'UNDICI-H2'
89-
})
90-
}
91-
9282
const session = http2.connect(client[kUrl], {
9383
createConnection: () => socket,
9484
peerMaxConcurrentStreams: client[kMaxConcurrentStreams],
Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict'
22

33
const assert = require('node:assert')
4+
const WrapHandler = require('./wrap-handler')
45

56
/**
67
* @deprecated
@@ -9,63 +10,58 @@ module.exports = class DecoratorHandler {
910
#handler
1011
#onCompleteCalled = false
1112
#onErrorCalled = false
13+
#onResponseStartCalled = false
1214

1315
constructor (handler) {
1416
if (typeof handler !== 'object' || handler === null) {
1517
throw new TypeError('handler must be an object')
1618
}
17-
this.#handler = handler
19+
this.#handler = WrapHandler.wrap(handler)
1820
}
1921

20-
onConnect (...args) {
21-
return this.#handler.onConnect?.(...args)
22+
onRequestStart (...args) {
23+
this.#handler.onRequestStart?.(...args)
2224
}
2325

24-
onError (...args) {
25-
this.#onErrorCalled = true
26-
return this.#handler.onError?.(...args)
27-
}
28-
29-
onUpgrade (...args) {
26+
onRequestUpgrade (...args) {
3027
assert(!this.#onCompleteCalled)
3128
assert(!this.#onErrorCalled)
3229

33-
return this.#handler.onUpgrade?.(...args)
30+
return this.#handler.onRequestUpgrade?.(...args)
3431
}
3532

36-
onResponseStarted (...args) {
33+
onResponseStart (...args) {
3734
assert(!this.#onCompleteCalled)
3835
assert(!this.#onErrorCalled)
36+
assert(!this.#onResponseStartCalled)
3937

40-
return this.#handler.onResponseStarted?.(...args)
41-
}
42-
43-
onHeaders (...args) {
44-
assert(!this.#onCompleteCalled)
45-
assert(!this.#onErrorCalled)
38+
this.#onResponseStartCalled = true
4639

47-
return this.#handler.onHeaders?.(...args)
40+
return this.#handler.onResponseStart?.(...args)
4841
}
4942

50-
onData (...args) {
43+
onResponseData (...args) {
5144
assert(!this.#onCompleteCalled)
5245
assert(!this.#onErrorCalled)
5346

54-
return this.#handler.onData?.(...args)
47+
return this.#handler.onResponseData?.(...args)
5548
}
5649

57-
onComplete (...args) {
50+
onResponseEnd (...args) {
5851
assert(!this.#onCompleteCalled)
5952
assert(!this.#onErrorCalled)
6053

6154
this.#onCompleteCalled = true
62-
return this.#handler.onComplete?.(...args)
55+
return this.#handler.onResponseEnd?.(...args)
6356
}
6457

65-
onBodySent (...args) {
66-
assert(!this.#onCompleteCalled)
67-
assert(!this.#onErrorCalled)
68-
69-
return this.#handler.onBodySent?.(...args)
58+
onResponseError (...args) {
59+
this.#onErrorCalled = true
60+
return this.#handler.onResponseError?.(...args)
7061
}
62+
63+
/**
64+
* @deprecated
65+
*/
66+
onBodySent () {}
7167
}

deps/undici/src/lib/interceptor/dns.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,27 +222,27 @@ class DNSDispatchHandler extends DecoratorHandler {
222222
#state = null
223223
#opts = null
224224
#dispatch = null
225-
#handler = null
226225
#origin = null
226+
#controller = null
227227

228228
constructor (state, { origin, handler, dispatch }, opts) {
229229
super(handler)
230230
this.#origin = origin
231-
this.#handler = handler
232231
this.#opts = { ...opts }
233232
this.#state = state
234233
this.#dispatch = dispatch
235234
}
236235

237-
onError (err) {
236+
onResponseError (controller, err) {
238237
switch (err.code) {
239238
case 'ETIMEDOUT':
240239
case 'ECONNREFUSED': {
241240
if (this.#state.dualStack) {
242241
// We delete the record and retry
243242
this.#state.runLookup(this.#origin, this.#opts, (err, newOrigin) => {
244243
if (err) {
245-
return this.#handler.onError(err)
244+
super.onResponseError(controller, err)
245+
return
246246
}
247247

248248
const dispatchOpts = {
@@ -253,18 +253,18 @@ class DNSDispatchHandler extends DecoratorHandler {
253253
this.#dispatch(dispatchOpts, this)
254254
})
255255

256-
// if dual-stack disabled, we error out
257256
return
258257
}
259258

260-
this.#handler.onError(err)
261-
return
259+
// if dual-stack disabled, we error out
260+
super.onResponseError(controller, err)
261+
break
262262
}
263263
case 'ENOTFOUND':
264264
this.#state.deleteRecord(this.#origin)
265265
// eslint-disable-next-line no-fallthrough
266266
default:
267-
this.#handler.onError(err)
267+
super.onResponseError(controller, err)
268268
break
269269
}
270270
}

0 commit comments

Comments
 (0)