Skip to content

Commit af789d9

Browse files
nodejs-github-botaduh95
authored andcommitted
deps: update undici to 7.12.0
PR-URL: #59135 Reviewed-By: Marco Ippolito <[email protected]> Reviewed-By: Rafael Gonzaga <[email protected]> Reviewed-By: Matthew Aitken <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
1 parent a34e445 commit af789d9

34 files changed

+1085
-954
lines changed

deps/undici/src/.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,3 +88,7 @@ undici-fetch.js
8888

8989
# File generated by /test/request-timeout.js
9090
test/request-timeout.10mb.bin
91+
92+
# Claude files
93+
CLAUDE.md
94+
.claude

deps/undici/src/README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,10 @@ const response = await fetch('https://api.example.com/data');
114114
#### Use Built-in Fetch When:
115115
- You want zero dependencies
116116
- Building isomorphic code that runs in browsers and Node.js
117+
- Publishing to npm and want to maximize compatibility with JS runtimes
117118
- Simple HTTP requests without advanced configuration
118-
- You're okay with the undici version bundled in your Node.js version
119+
- You're publishing to npm and you want to maximize compatiblity
120+
- You don't depend on features from a specific version of undici
119121

120122
#### Use Undici Module When:
121123
- You need the latest undici features and performance improvements
@@ -209,7 +211,7 @@ The `install()` function adds the following classes to `globalThis`:
209211
- `fetch` - The fetch function
210212
- `Headers` - HTTP headers management
211213
- `Response` - HTTP response representation
212-
- `Request` - HTTP request representation
214+
- `Request` - HTTP request representation
213215
- `FormData` - Form data handling
214216
- `WebSocket` - WebSocket client
215217
- `CloseEvent`, `ErrorEvent`, `MessageEvent` - WebSocket events

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,10 +169,11 @@ This message is published after the client has successfully connected to a serve
169169
```js
170170
import diagnosticsChannel from 'diagnostics_channel'
171171

172-
diagnosticsChannel.channel('undici:websocket:open').subscribe(({ address, protocol, extensions }) => {
172+
diagnosticsChannel.channel('undici:websocket:open').subscribe(({ address, protocol, extensions, websocket }) => {
173173
console.log(address) // address, family, and port
174174
console.log(protocol) // negotiated subprotocols
175175
console.log(extensions) // negotiated extensions
176+
console.log(websocket) // the WebSocket instance
176177
})
177178
```
178179

@@ -184,7 +185,7 @@ This message is published after the connection has closed.
184185
import diagnosticsChannel from 'diagnostics_channel'
185186

186187
diagnosticsChannel.channel('undici:websocket:close').subscribe(({ websocket, code, reason }) => {
187-
console.log(websocket) // the WebSocket object
188+
console.log(websocket) // the WebSocket instance
188189
console.log(code) // the closing status code
189190
console.log(reason) // the closing reason
190191
})
@@ -209,9 +210,10 @@ This message is published after the client receives a ping frame, if the connect
209210
```js
210211
import diagnosticsChannel from 'diagnostics_channel'
211212

212-
diagnosticsChannel.channel('undici:websocket:ping').subscribe(({ payload }) => {
213+
diagnosticsChannel.channel('undici:websocket:ping').subscribe(({ payload, websocket }) => {
213214
// a Buffer or undefined, containing the optional application data of the frame
214215
console.log(payload)
216+
console.log(websocket) // the WebSocket instance
215217
})
216218
```
217219

@@ -222,8 +224,9 @@ This message is published after the client receives a pong frame.
222224
```js
223225
import diagnosticsChannel from 'diagnostics_channel'
224226

225-
diagnosticsChannel.channel('undici:websocket:pong').subscribe(({ payload }) => {
227+
diagnosticsChannel.channel('undici:websocket:pong').subscribe(({ payload, websocket }) => {
226228
// a Buffer or undefined, containing the optional application data of the frame
227229
console.log(payload)
230+
console.log(websocket) // the WebSocket instance
228231
})
229232
```

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,8 +1103,8 @@ The `cache` interceptor implements client-side response caching as described in
11031103

11041104
- `store` - The [`CacheStore`](/docs/docs/api/CacheStore.md) to store and retrieve responses from. Default is [`MemoryCacheStore`](/docs/docs/api/CacheStore.md#memorycachestore).
11051105
- `methods` - The [**safe** HTTP methods](https://www.rfc-editor.org/rfc/rfc9110#section-9.2.1) to cache the response of.
1106-
- `cacheByDefault` - The default expiration time to cache responses by if they don't have an explicit expiration. If this isn't present, responses without explicit expiration will not be cached. Default `undefined`.
1107-
- `type` - The type of cache for Undici to act as. Can be `shared` or `private`. Default `shared`.
1106+
- `cacheByDefault` - The default expiration time to cache responses by if they don't have an explicit expiration and cannot have an heuristic expiry computed. If this isn't present, responses neither with an explicit expiration nor heuristically cacheable will not be cached. Default `undefined`.
1107+
- `type` - The [type of cache](https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/Caching#types_of_caches) for Undici to act as. Can be `shared` or `private`. Default `shared`. `private` implies privately cacheable responses will be cached and potentially shared with other users of your application.
11081108

11091109
## Instance Events
11101110

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,33 @@ setInterval(() => write(), 5000)
7878

7979
```
8080

81+
## ping(websocket, payload)
82+
Arguments:
83+
84+
* **websocket** `WebSocket` - The WebSocket instance to send the ping frame on
85+
* **payload** `Buffer|undefined` (optional) - Optional payload data to include with the ping frame. Must not exceed 125 bytes.
86+
87+
Sends a ping frame to the WebSocket server. The server must respond with a pong frame containing the same payload data. This can be used for keepalive purposes or to verify that the connection is still active.
88+
89+
### Example:
90+
91+
```js
92+
import { WebSocket, ping } from 'undici'
93+
94+
const ws = new WebSocket('wss://echo.websocket.events')
95+
96+
ws.addEventListener('open', () => {
97+
// Send ping with no payload
98+
ping(ws)
99+
100+
// Send ping with payload
101+
const payload = Buffer.from('hello')
102+
ping(ws, payload)
103+
})
104+
```
105+
106+
**Note**: A ping frame cannot have a payload larger than 125 bytes. The ping will only be sent if the WebSocket connection is in the OPEN state.
107+
81108
## Read More
82109

83110
- [MDN - WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket)

deps/undici/src/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,12 @@ module.exports.parseMIMEType = parseMIMEType
157157
module.exports.serializeAMimeType = serializeAMimeType
158158

159159
const { CloseEvent, ErrorEvent, MessageEvent } = require('./lib/web/websocket/events')
160-
module.exports.WebSocket = require('./lib/web/websocket/websocket').WebSocket
160+
const { WebSocket, ping } = require('./lib/web/websocket/websocket')
161+
module.exports.WebSocket = WebSocket
161162
module.exports.CloseEvent = CloseEvent
162163
module.exports.ErrorEvent = ErrorEvent
163164
module.exports.MessageEvent = MessageEvent
165+
module.exports.ping = ping
164166

165167
module.exports.WebSocketStream = require('./lib/web/websocket/stream/websocketstream').WebSocketStream
166168
module.exports.WebSocketError = require('./lib/web/websocket/stream/websocketerror').WebSocketError

deps/undici/src/lib/api/readable.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ class BodyReadable extends Readable {
8989
// promise (i.e micro tick) for installing an 'error' listener will
9090
// never get a chance and will always encounter an unhandled exception.
9191
if (!this[kUsed]) {
92-
setImmediate(() => {
93-
callback(err)
94-
})
92+
setImmediate(callback, err)
9593
} else {
9694
callback(err)
9795
}

deps/undici/src/lib/core/request.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ class Request {
4242
reset,
4343
expectContinue,
4444
servername,
45-
throwOnError
45+
throwOnError,
46+
maxRedirections
4647
}, handler) {
4748
if (typeof path !== 'string') {
4849
throw new InvalidArgumentError('path must be a string')
@@ -86,6 +87,10 @@ class Request {
8687
throw new InvalidArgumentError('invalid throwOnError')
8788
}
8889

90+
if (maxRedirections != null && maxRedirections !== 0) {
91+
throw new InvalidArgumentError('maxRedirections is not supported, use the redirect interceptor')
92+
}
93+
8994
this.headersTimeout = headersTimeout
9095

9196
this.bodyTimeout = bodyTimeout

deps/undici/src/lib/core/tree.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class TstNode {
8686

8787
/**
8888
* @param {Uint8Array} key
89-
* @return {TstNode | null}
89+
* @returns {TstNode | null}
9090
*/
9191
search (key) {
9292
const keylength = key.length

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

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,23 @@ const removeAllListeners = util.removeAllListeners
6060

6161
let extractBody
6262

63-
async function lazyllhttp () {
63+
function lazyllhttp () {
6464
const llhttpWasmData = process.env.JEST_WORKER_ID ? require('../llhttp/llhttp-wasm.js') : undefined
6565

6666
let mod
6767
try {
68-
mod = await WebAssembly.compile(require('../llhttp/llhttp_simd-wasm.js'))
68+
mod = new WebAssembly.Module(require('../llhttp/llhttp_simd-wasm.js'))
6969
} catch (e) {
7070
/* istanbul ignore next */
7171

7272
// We could check if the error was caused by the simd option not
7373
// being enabled, but the occurring of this other error
7474
// * https://github.com/emscripten-core/emscripten/issues/11495
7575
// got me to remove that check to avoid breaking Node 12.
76-
mod = await WebAssembly.compile(llhttpWasmData || require('../llhttp/llhttp-wasm.js'))
76+
mod = new WebAssembly.Module(llhttpWasmData || require('../llhttp/llhttp-wasm.js'))
7777
}
7878

79-
return await WebAssembly.instantiate(mod, {
79+
return new WebAssembly.Instance(mod, {
8080
env: {
8181
/**
8282
* @param {number} p
@@ -165,11 +165,6 @@ async function lazyllhttp () {
165165
}
166166

167167
let llhttpInstance = null
168-
/**
169-
* @type {Promise<WebAssembly.Instance>|null}
170-
*/
171-
let llhttpPromise = lazyllhttp()
172-
llhttpPromise.catch()
173168

174169
/**
175170
* @type {Parser|null}
@@ -732,7 +727,7 @@ class Parser {
732727
// We must wait a full event loop cycle to reuse this socket to make sure
733728
// that non-spec compliant servers are not closing the connection even if they
734729
// said they won't.
735-
setImmediate(() => client[kResume]())
730+
setImmediate(client[kResume])
736731
} else {
737732
client[kResume]()
738733
}
@@ -769,11 +764,7 @@ async function connectH1 (client, socket) {
769764
client[kSocket] = socket
770765

771766
if (!llhttpInstance) {
772-
const noop = () => {}
773-
socket.on('error', noop)
774-
llhttpInstance = await llhttpPromise
775-
llhttpPromise = null
776-
socket.off('error', noop)
767+
llhttpInstance = lazyllhttp()
777768
}
778769

779770
if (socket.errored) {
@@ -1297,9 +1288,9 @@ function writeStream (abort, body, client, request, socket, contentLength, heade
12971288
.on('error', onFinished)
12981289

12991290
if (body.errorEmitted ?? body.errored) {
1300-
setImmediate(() => onFinished(body.errored))
1291+
setImmediate(onFinished, body.errored)
13011292
} else if (body.endEmitted ?? body.readableEnded) {
1302-
setImmediate(() => onFinished(null))
1293+
setImmediate(onFinished, null)
13031294
}
13041295

13051296
if (body.closeEmitted ?? body.closed) {

0 commit comments

Comments
 (0)