Skip to content

Commit e8f2c0a

Browse files
nodejs-github-botMoLow
authored andcommitted
deps: update undici to 5.22.1
PR-URL: #47994 Reviewed-By: Matthew Aitken <maitken033380023@gmail.com> Reviewed-By: Moshe Atlow <moshe@atlow.co.il> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Mestery <mestery@protonmail.com>
1 parent ce859f9 commit e8f2c0a

27 files changed

+1422
-78
lines changed
+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# CacheStorage
2+
3+
Undici exposes a W3C spec-compliant implementation of [CacheStorage](https://developer.mozilla.org/en-US/docs/Web/API/CacheStorage) and [Cache](https://developer.mozilla.org/en-US/docs/Web/API/Cache).
4+
5+
## Opening a Cache
6+
7+
Undici exports a top-level CacheStorage instance. You can open a new Cache, or duplicate a Cache with an existing name, by using `CacheStorage.prototype.open`. If you open a Cache with the same name as an already-existing Cache, its list of cached Responses will be shared between both instances.
8+
9+
```mjs
10+
import { caches } from 'undici'
11+
12+
const cache_1 = await caches.open('v1')
13+
const cache_2 = await caches.open('v1')
14+
15+
// Although .open() creates a new instance,
16+
assert(cache_1 !== cache_2)
17+
// The same Response is matched in both.
18+
assert.deepStrictEqual(await cache_1.match('/req'), await cache_2.match('/req'))
19+
```
20+
21+
## Deleting a Cache
22+
23+
If a Cache is deleted, the cached Responses/Requests can still be used.
24+
25+
```mjs
26+
const response = await cache_1.match('/req')
27+
await caches.delete('v1')
28+
29+
await response.text() // the Response's body
30+
```

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

+19-13
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,25 @@ You can find all the error objects inside the `errors` key.
77
import { errors } from 'undici'
88
```
99

10-
| Error | Error Codes | Description |
11-
| ------------------------------------ | ------------------------------------- | -------------------------------------------------- |
12-
| `InvalidArgumentError` | `UND_ERR_INVALID_ARG` | passed an invalid argument. |
13-
| `InvalidReturnValueError` | `UND_ERR_INVALID_RETURN_VALUE` | returned an invalid value. |
14-
| `RequestAbortedError` | `UND_ERR_ABORTED` | the request has been aborted by the user |
15-
| `ClientDestroyedError` | `UND_ERR_DESTROYED` | trying to use a destroyed client. |
16-
| `ClientClosedError` | `UND_ERR_CLOSED` | trying to use a closed client. |
17-
| `SocketError` | `UND_ERR_SOCKET` | there is an error with the socket. |
18-
| `NotSupportedError` | `UND_ERR_NOT_SUPPORTED` | encountered unsupported functionality. |
19-
| `RequestContentLengthMismatchError` | `UND_ERR_REQ_CONTENT_LENGTH_MISMATCH` | request body does not match content-length header |
20-
| `ResponseContentLengthMismatchError` | `UND_ERR_RES_CONTENT_LENGTH_MISMATCH` | response body does not match content-length header |
21-
| `InformationalError` | `UND_ERR_INFO` | expected error with reason |
22-
| `ResponseExceededMaxSizeError` | `UND_ERR_RES_EXCEEDED_MAX_SIZE` | response body exceed the max size allowed |
10+
| Error | Error Codes | Description |
11+
| ------------------------------------ | ------------------------------------- | ------------------------------------------------------------------------- |
12+
| `UndiciError` | `UND_ERR` | all errors below are extended from `UndiciError`. |
13+
| `ConnectTimeoutError` | `UND_ERR_CONNECT_TIMEOUT` | socket is destroyed due to connect timeout. |
14+
| `HeadersTimeoutError` | `UND_ERR_HEADERS_TIMEOUT` | socket is destroyed due to headers timeout. |
15+
| `HeadersOverflowError` | `UND_ERR_HEADERS_OVERFLOW` | socket is destroyed due to headers' max size being exceeded. |
16+
| `BodyTimeoutError` | `UND_ERR_BODY_TIMEOUT` | socket is destroyed due to body timeout. |
17+
| `ResponseStatusCodeError` | `UND_ERR_RESPONSE_STATUS_CODE` | an error is thrown when `throwOnError` is `true` for status codes >= 400. |
18+
| `InvalidArgumentError` | `UND_ERR_INVALID_ARG` | passed an invalid argument. |
19+
| `InvalidReturnValueError` | `UND_ERR_INVALID_RETURN_VALUE` | returned an invalid value. |
20+
| `RequestAbortedError` | `UND_ERR_ABORTED` | the request has been aborted by the user |
21+
| `ClientDestroyedError` | `UND_ERR_DESTROYED` | trying to use a destroyed client. |
22+
| `ClientClosedError` | `UND_ERR_CLOSED` | trying to use a closed client. |
23+
| `SocketError` | `UND_ERR_SOCKET` | there is an error with the socket. |
24+
| `NotSupportedError` | `UND_ERR_NOT_SUPPORTED` | encountered unsupported functionality. |
25+
| `RequestContentLengthMismatchError` | `UND_ERR_REQ_CONTENT_LENGTH_MISMATCH` | request body does not match content-length header |
26+
| `ResponseContentLengthMismatchError` | `UND_ERR_RES_CONTENT_LENGTH_MISMATCH` | response body does not match content-length header |
27+
| `InformationalError` | `UND_ERR_INFO` | expected error with reason |
28+
| `ResponseExceededMaxSizeError` | `UND_ERR_RES_EXCEEDED_MAX_SIZE` | response body exceed the max size allowed |
2329

2430
### `SocketError`
2531

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

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ Documentation and examples can be found on [MDN](https://developer.mozilla.org/e
88

99
This API is implemented as per the standard, you can find documentation on [MDN](https://developer.mozilla.org/en-US/docs/Web/API/File)
1010

11+
In Node versions v18.13.0 and above and v19.2.0 and above, undici will default to using Node's [File](https://nodejs.org/api/buffer.html#class-file) class. In versions where it's not available, it will default to the undici one.
12+
1113
## FormData
1214

1315
This API is implemented as per the standard, you can find documentation on [MDN](https://developer.mozilla.org/en-US/docs/Web/API/FormData)

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

+26-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,40 @@
11
# Class: WebSocket
22

3-
> ⚠️ Warning: the WebSocket API is experimental and has known bugs.
3+
> ⚠️ Warning: the WebSocket API is experimental.
44
55
Extends: [`EventTarget`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget)
66

7-
The WebSocket object provides a way to manage a WebSocket connection to a server, allowing bidirectional communication. The API follows the [WebSocket spec](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket).
7+
The WebSocket object provides a way to manage a WebSocket connection to a server, allowing bidirectional communication. The API follows the [WebSocket spec](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket) and [RFC 6455](https://datatracker.ietf.org/doc/html/rfc6455).
88

99
## `new WebSocket(url[, protocol])`
1010

1111
Arguments:
1212

1313
* **url** `URL | string` - The url's protocol *must* be `ws` or `wss`.
14-
* **protocol** `string | string[]` (optional) - Subprotocol(s) to request the server use.
14+
* **protocol** `string | string[] | WebSocketInit` (optional) - Subprotocol(s) to request the server use, or a [`Dispatcher`](./Dispatcher.md).
15+
16+
### Example:
17+
18+
This example will not work in browsers or other platforms that don't allow passing an object.
19+
20+
```mjs
21+
import { WebSocket, ProxyAgent } from 'undici'
22+
23+
const proxyAgent = new ProxyAgent('my.proxy.server')
24+
25+
const ws = new WebSocket('wss://echo.websocket.events', {
26+
dispatcher: proxyAgent,
27+
protocols: ['echo', 'chat']
28+
})
29+
```
30+
31+
If you do not need a custom Dispatcher, it's recommended to use the following pattern:
32+
33+
```mjs
34+
import { WebSocket } from 'undici'
35+
36+
const ws = new WebSocket('wss://echo.websocket.events', ['echo', 'chat'])
37+
```
1538

1639
## Read More
1740

deps/undici/src/index.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export * from './types/formdata'
2424
export * from './types/diagnostics-channel'
2525
export * from './types/websocket'
2626
export * from './types/content-type'
27+
export * from './types/cache'
2728
export { Interceptable } from './types/mock-interceptor'
2829

2930
export { Dispatcher, BalancedPool, Pool, Client, buildConnector, errors, Agent, request, stream, pipeline, connect, upgrade, setGlobalDispatcher, getGlobalDispatcher, setGlobalOrigin, getGlobalOrigin, MockClient, MockPool, MockAgent, mockErrors, ProxyAgent, RedirectHandler, DecoratorHandler }
@@ -52,4 +53,5 @@ declare namespace Undici {
5253
var MockAgent: typeof import('./types/mock-agent').default;
5354
var mockErrors: typeof import('./types/mock-errors').default;
5455
var fetch: typeof import('./types/fetch').fetch;
56+
var caches: typeof import('./types/cache').caches;
5557
}

deps/undici/src/index.js

+7
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,13 @@ if (util.nodeMajor > 16 || (util.nodeMajor === 16 && util.nodeMinor >= 8)) {
121121

122122
module.exports.setGlobalOrigin = setGlobalOrigin
123123
module.exports.getGlobalOrigin = getGlobalOrigin
124+
125+
const { CacheStorage } = require('./lib/cache/cachestorage')
126+
const { kConstruct } = require('./lib/cache/symbols')
127+
128+
// Cache & CacheStorage are tightly coupled with fetch. Even if it may run
129+
// in an older version of Node, it doesn't have any use without fetch.
130+
module.exports.caches = new CacheStorage(kConstruct)
124131
}
125132

126133
if (util.nodeMajor >= 16) {

0 commit comments

Comments
 (0)