@depup/undici 7.24.3-depup.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +25 -0
- package/changes.json +5 -0
- package/docs/docs/api/Agent.md +84 -0
- package/docs/docs/api/BalancedPool.md +99 -0
- package/docs/docs/api/CacheStorage.md +30 -0
- package/docs/docs/api/CacheStore.md +164 -0
- package/docs/docs/api/Client.md +285 -0
- package/docs/docs/api/ClientStats.md +27 -0
- package/docs/docs/api/Connector.md +115 -0
- package/docs/docs/api/ContentType.md +57 -0
- package/docs/docs/api/Cookies.md +101 -0
- package/docs/docs/api/Debug.md +62 -0
- package/docs/docs/api/DiagnosticsChannel.md +313 -0
- package/docs/docs/api/Dispatcher.md +1392 -0
- package/docs/docs/api/EnvHttpProxyAgent.md +159 -0
- package/docs/docs/api/Errors.md +49 -0
- package/docs/docs/api/EventSource.md +45 -0
- package/docs/docs/api/Fetch.md +52 -0
- package/docs/docs/api/GlobalInstallation.md +91 -0
- package/docs/docs/api/H2CClient.md +263 -0
- package/docs/docs/api/MockAgent.md +603 -0
- package/docs/docs/api/MockCallHistory.md +197 -0
- package/docs/docs/api/MockCallHistoryLog.md +43 -0
- package/docs/docs/api/MockClient.md +81 -0
- package/docs/docs/api/MockErrors.md +12 -0
- package/docs/docs/api/MockPool.md +555 -0
- package/docs/docs/api/Pool.md +84 -0
- package/docs/docs/api/PoolStats.md +35 -0
- package/docs/docs/api/ProxyAgent.md +229 -0
- package/docs/docs/api/RedirectHandler.md +96 -0
- package/docs/docs/api/RetryAgent.md +50 -0
- package/docs/docs/api/RetryHandler.md +118 -0
- package/docs/docs/api/RoundRobinPool.md +145 -0
- package/docs/docs/api/SnapshotAgent.md +616 -0
- package/docs/docs/api/Socks5ProxyAgent.md +274 -0
- package/docs/docs/api/Util.md +25 -0
- package/docs/docs/api/WebSocket.md +141 -0
- package/docs/docs/api/api-lifecycle.md +91 -0
- package/docs/docs/best-practices/client-certificate.md +64 -0
- package/docs/docs/best-practices/crawling.md +58 -0
- package/docs/docs/best-practices/mocking-request.md +190 -0
- package/docs/docs/best-practices/proxy.md +127 -0
- package/docs/docs/best-practices/undici-vs-builtin-fetch.md +137 -0
- package/docs/docs/best-practices/writing-tests.md +20 -0
- package/index-fetch.js +65 -0
- package/index.d.ts +3 -0
- package/index.js +234 -0
- package/lib/api/abort-signal.js +59 -0
- package/lib/api/api-connect.js +110 -0
- package/lib/api/api-pipeline.js +252 -0
- package/lib/api/api-request.js +214 -0
- package/lib/api/api-stream.js +209 -0
- package/lib/api/api-upgrade.js +111 -0
- package/lib/api/index.js +7 -0
- package/lib/api/readable.js +580 -0
- package/lib/cache/memory-cache-store.js +234 -0
- package/lib/cache/sqlite-cache-store.js +461 -0
- package/lib/core/connect.js +137 -0
- package/lib/core/constants.js +143 -0
- package/lib/core/diagnostics.js +225 -0
- package/lib/core/errors.js +477 -0
- package/lib/core/request.js +430 -0
- package/lib/core/socks5-client.js +407 -0
- package/lib/core/socks5-utils.js +203 -0
- package/lib/core/symbols.js +75 -0
- package/lib/core/tree.js +160 -0
- package/lib/core/util.js +972 -0
- package/lib/dispatcher/agent.js +158 -0
- package/lib/dispatcher/balanced-pool.js +219 -0
- package/lib/dispatcher/client-h1.js +1610 -0
- package/lib/dispatcher/client-h2.js +995 -0
- package/lib/dispatcher/client.js +654 -0
- package/lib/dispatcher/dispatcher-base.js +165 -0
- package/lib/dispatcher/dispatcher.js +48 -0
- package/lib/dispatcher/env-http-proxy-agent.js +146 -0
- package/lib/dispatcher/fixed-queue.js +135 -0
- package/lib/dispatcher/h2c-client.js +51 -0
- package/lib/dispatcher/pool-base.js +214 -0
- package/lib/dispatcher/pool.js +118 -0
- package/lib/dispatcher/proxy-agent.js +318 -0
- package/lib/dispatcher/retry-agent.js +35 -0
- package/lib/dispatcher/round-robin-pool.js +137 -0
- package/lib/dispatcher/socks5-proxy-agent.js +249 -0
- package/lib/encoding/index.js +33 -0
- package/lib/global.js +50 -0
- package/lib/handler/cache-handler.js +561 -0
- package/lib/handler/cache-revalidation-handler.js +124 -0
- package/lib/handler/decorator-handler.js +67 -0
- package/lib/handler/deduplication-handler.js +460 -0
- package/lib/handler/redirect-handler.js +238 -0
- package/lib/handler/retry-handler.js +394 -0
- package/lib/handler/unwrap-handler.js +100 -0
- package/lib/handler/wrap-handler.js +105 -0
- package/lib/interceptor/cache.js +495 -0
- package/lib/interceptor/decompress.js +259 -0
- package/lib/interceptor/deduplicate.js +117 -0
- package/lib/interceptor/dns.js +571 -0
- package/lib/interceptor/dump.js +112 -0
- package/lib/interceptor/redirect.js +21 -0
- package/lib/interceptor/response-error.js +95 -0
- package/lib/interceptor/retry.js +19 -0
- package/lib/llhttp/.gitkeep +0 -0
- package/lib/llhttp/constants.d.ts +195 -0
- package/lib/llhttp/constants.js +531 -0
- package/lib/llhttp/llhttp-wasm.js +15 -0
- package/lib/llhttp/llhttp_simd-wasm.js +15 -0
- package/lib/llhttp/utils.d.ts +2 -0
- package/lib/llhttp/utils.js +12 -0
- package/lib/mock/mock-agent.js +232 -0
- package/lib/mock/mock-call-history.js +248 -0
- package/lib/mock/mock-client.js +68 -0
- package/lib/mock/mock-errors.js +29 -0
- package/lib/mock/mock-interceptor.js +209 -0
- package/lib/mock/mock-pool.js +68 -0
- package/lib/mock/mock-symbols.js +31 -0
- package/lib/mock/mock-utils.js +480 -0
- package/lib/mock/pending-interceptors-formatter.js +43 -0
- package/lib/mock/snapshot-agent.js +353 -0
- package/lib/mock/snapshot-recorder.js +588 -0
- package/lib/mock/snapshot-utils.js +158 -0
- package/lib/util/cache.js +407 -0
- package/lib/util/date.js +653 -0
- package/lib/util/promise.js +28 -0
- package/lib/util/runtime-features.js +124 -0
- package/lib/util/stats.js +32 -0
- package/lib/util/timers.js +425 -0
- package/lib/web/cache/cache.js +864 -0
- package/lib/web/cache/cachestorage.js +152 -0
- package/lib/web/cache/util.js +45 -0
- package/lib/web/cookies/constants.js +12 -0
- package/lib/web/cookies/index.js +199 -0
- package/lib/web/cookies/parse.js +322 -0
- package/lib/web/cookies/util.js +282 -0
- package/lib/web/eventsource/eventsource-stream.js +399 -0
- package/lib/web/eventsource/eventsource.js +501 -0
- package/lib/web/eventsource/util.js +29 -0
- package/lib/web/fetch/LICENSE +21 -0
- package/lib/web/fetch/body.js +509 -0
- package/lib/web/fetch/constants.js +131 -0
- package/lib/web/fetch/data-url.js +596 -0
- package/lib/web/fetch/formdata-parser.js +575 -0
- package/lib/web/fetch/formdata.js +259 -0
- package/lib/web/fetch/global.js +40 -0
- package/lib/web/fetch/headers.js +719 -0
- package/lib/web/fetch/index.js +2378 -0
- package/lib/web/fetch/request.js +1115 -0
- package/lib/web/fetch/response.js +641 -0
- package/lib/web/fetch/util.js +1520 -0
- package/lib/web/infra/index.js +229 -0
- package/lib/web/subresource-integrity/Readme.md +9 -0
- package/lib/web/subresource-integrity/subresource-integrity.js +307 -0
- package/lib/web/webidl/index.js +1006 -0
- package/lib/web/websocket/connection.js +329 -0
- package/lib/web/websocket/constants.js +126 -0
- package/lib/web/websocket/events.js +331 -0
- package/lib/web/websocket/frame.js +133 -0
- package/lib/web/websocket/permessage-deflate.js +118 -0
- package/lib/web/websocket/receiver.js +450 -0
- package/lib/web/websocket/sender.js +109 -0
- package/lib/web/websocket/stream/websocketerror.js +104 -0
- package/lib/web/websocket/stream/websocketstream.js +497 -0
- package/lib/web/websocket/util.js +347 -0
- package/lib/web/websocket/websocket.js +739 -0
- package/package.json +163 -0
- package/scripts/strip-comments.js +10 -0
- package/types/README.md +6 -0
- package/types/agent.d.ts +32 -0
- package/types/api.d.ts +43 -0
- package/types/balanced-pool.d.ts +30 -0
- package/types/cache-interceptor.d.ts +179 -0
- package/types/cache.d.ts +36 -0
- package/types/client-stats.d.ts +15 -0
- package/types/client.d.ts +123 -0
- package/types/connector.d.ts +36 -0
- package/types/content-type.d.ts +21 -0
- package/types/cookies.d.ts +30 -0
- package/types/diagnostics-channel.d.ts +74 -0
- package/types/dispatcher.d.ts +279 -0
- package/types/env-http-proxy-agent.d.ts +22 -0
- package/types/errors.d.ts +177 -0
- package/types/eventsource.d.ts +66 -0
- package/types/fetch.d.ts +211 -0
- package/types/formdata.d.ts +108 -0
- package/types/global-dispatcher.d.ts +9 -0
- package/types/global-origin.d.ts +7 -0
- package/types/h2c-client.d.ts +73 -0
- package/types/handlers.d.ts +15 -0
- package/types/header.d.ts +160 -0
- package/types/index.d.ts +91 -0
- package/types/interceptors.d.ts +80 -0
- package/types/mock-agent.d.ts +68 -0
- package/types/mock-call-history.d.ts +111 -0
- package/types/mock-client.d.ts +27 -0
- package/types/mock-errors.d.ts +12 -0
- package/types/mock-interceptor.d.ts +94 -0
- package/types/mock-pool.d.ts +27 -0
- package/types/patch.d.ts +29 -0
- package/types/pool-stats.d.ts +19 -0
- package/types/pool.d.ts +41 -0
- package/types/proxy-agent.d.ts +29 -0
- package/types/readable.d.ts +68 -0
- package/types/retry-agent.d.ts +8 -0
- package/types/retry-handler.d.ts +125 -0
- package/types/round-robin-pool.d.ts +41 -0
- package/types/snapshot-agent.d.ts +109 -0
- package/types/socks5-proxy-agent.d.ts +25 -0
- package/types/util.d.ts +18 -0
- package/types/utility.d.ts +7 -0
- package/types/webidl.d.ts +347 -0
- package/types/websocket.d.ts +188 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) Matteo Collina and Undici contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# @depup/undici
|
|
2
|
+
|
|
3
|
+
> Dependency-bumped version of [undici](https://www.npmjs.com/package/undici)
|
|
4
|
+
|
|
5
|
+
Generated by [DepUp](https://github.com/depup/npm) -- all production
|
|
6
|
+
dependencies bumped to latest versions.
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
```bash
|
|
11
|
+
npm install @depup/undici
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
| Field | Value |
|
|
15
|
+
|-------|-------|
|
|
16
|
+
| Original | [undici](https://www.npmjs.com/package/undici) @ 7.24.3 |
|
|
17
|
+
| Processed | 2026-03-14 |
|
|
18
|
+
| Smoke test | passed |
|
|
19
|
+
| Deps updated | 0 |
|
|
20
|
+
|
|
21
|
+
---
|
|
22
|
+
|
|
23
|
+
Source: https://github.com/depup/npm | Original: https://www.npmjs.com/package/undici
|
|
24
|
+
|
|
25
|
+
License inherited from the original package.
|
package/changes.json
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# Agent
|
|
2
|
+
|
|
3
|
+
Extends: `undici.Dispatcher`
|
|
4
|
+
|
|
5
|
+
Agent allows dispatching requests against multiple different origins.
|
|
6
|
+
|
|
7
|
+
Requests are not guaranteed to be dispatched in order of invocation.
|
|
8
|
+
|
|
9
|
+
## `new undici.Agent([options])`
|
|
10
|
+
|
|
11
|
+
Arguments:
|
|
12
|
+
|
|
13
|
+
* **options** `AgentOptions` (optional)
|
|
14
|
+
|
|
15
|
+
Returns: `Agent`
|
|
16
|
+
|
|
17
|
+
### Parameter: `AgentOptions`
|
|
18
|
+
|
|
19
|
+
Extends: [`PoolOptions`](/docs/docs/api/Pool.md#parameter-pooloptions)
|
|
20
|
+
|
|
21
|
+
* **factory** `(origin: URL, opts: Object) => Dispatcher` - Default: `(origin, opts) => new Pool(origin, opts)`
|
|
22
|
+
* **maxOrigins** `number` (optional) - Default: `Infinity` - Limits the total number of origins that can receive requests at a time, throwing an `MaxOriginsReachedError` error when attempting to dispatch when the max is reached. If `Infinity`, no limit is enforced.
|
|
23
|
+
|
|
24
|
+
## Instance Properties
|
|
25
|
+
|
|
26
|
+
### `Agent.closed`
|
|
27
|
+
|
|
28
|
+
Implements [Client.closed](/docs/docs/api/Client.md#clientclosed)
|
|
29
|
+
|
|
30
|
+
### `Agent.destroyed`
|
|
31
|
+
|
|
32
|
+
Implements [Client.destroyed](/docs/docs/api/Client.md#clientdestroyed)
|
|
33
|
+
|
|
34
|
+
## Instance Methods
|
|
35
|
+
|
|
36
|
+
### `Agent.close([callback])`
|
|
37
|
+
|
|
38
|
+
Implements [`Dispatcher.close([callback])`](/docs/docs/api/Dispatcher.md#dispatcherclosecallback-promise).
|
|
39
|
+
|
|
40
|
+
### `Agent.destroy([error, callback])`
|
|
41
|
+
|
|
42
|
+
Implements [`Dispatcher.destroy([error, callback])`](/docs/docs/api/Dispatcher.md#dispatcherdestroyerror-callback-promise).
|
|
43
|
+
|
|
44
|
+
### `Agent.dispatch(options, handler: AgentDispatchOptions)`
|
|
45
|
+
|
|
46
|
+
Implements [`Dispatcher.dispatch(options, handler)`](/docs/docs/api/Dispatcher.md#dispatcherdispatchoptions-handler).
|
|
47
|
+
|
|
48
|
+
#### Parameter: `AgentDispatchOptions`
|
|
49
|
+
|
|
50
|
+
Extends: [`DispatchOptions`](/docs/docs/api/Dispatcher.md#parameter-dispatchoptions)
|
|
51
|
+
|
|
52
|
+
* **origin** `string | URL`
|
|
53
|
+
|
|
54
|
+
Implements [`Dispatcher.destroy([error, callback])`](/docs/docs/api/Dispatcher.md#dispatcherdestroyerror-callback-promise).
|
|
55
|
+
|
|
56
|
+
### `Agent.connect(options[, callback])`
|
|
57
|
+
|
|
58
|
+
See [`Dispatcher.connect(options[, callback])`](/docs/docs/api/Dispatcher.md#dispatcherconnectoptions-callback).
|
|
59
|
+
|
|
60
|
+
### `Agent.dispatch(options, handler)`
|
|
61
|
+
|
|
62
|
+
Implements [`Dispatcher.dispatch(options, handler)`](/docs/docs/api/Dispatcher.md#dispatcherdispatchoptions-handler).
|
|
63
|
+
|
|
64
|
+
### `Agent.pipeline(options, handler)`
|
|
65
|
+
|
|
66
|
+
See [`Dispatcher.pipeline(options, handler)`](/docs/docs/api/Dispatcher.md#dispatcherpipelineoptions-handler).
|
|
67
|
+
|
|
68
|
+
### `Agent.request(options[, callback])`
|
|
69
|
+
|
|
70
|
+
See [`Dispatcher.request(options [, callback])`](/docs/docs/api/Dispatcher.md#dispatcherrequestoptions-callback).
|
|
71
|
+
|
|
72
|
+
### `Agent.stream(options, factory[, callback])`
|
|
73
|
+
|
|
74
|
+
See [`Dispatcher.stream(options, factory[, callback])`](/docs/docs/api/Dispatcher.md#dispatcherstreamoptions-factory-callback).
|
|
75
|
+
|
|
76
|
+
### `Agent.upgrade(options[, callback])`
|
|
77
|
+
|
|
78
|
+
See [`Dispatcher.upgrade(options[, callback])`](/docs/docs/api/Dispatcher.md#dispatcherupgradeoptions-callback).
|
|
79
|
+
|
|
80
|
+
### `Agent.stats()`
|
|
81
|
+
|
|
82
|
+
Returns an object of stats by origin in the format of `Record<string, TClientStats | TPoolStats>`
|
|
83
|
+
|
|
84
|
+
See [`PoolStats`](/docs/docs/api/PoolStats.md) and [`ClientStats`](/docs/docs/api/ClientStats.md).
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Class: BalancedPool
|
|
2
|
+
|
|
3
|
+
Extends: `undici.Dispatcher`
|
|
4
|
+
|
|
5
|
+
A pool of [Pool](/docs/docs/api/Pool.md) instances connected to multiple upstreams.
|
|
6
|
+
|
|
7
|
+
Requests are not guaranteed to be dispatched in order of invocation.
|
|
8
|
+
|
|
9
|
+
## `new BalancedPool(upstreams [, options])`
|
|
10
|
+
|
|
11
|
+
Arguments:
|
|
12
|
+
|
|
13
|
+
* **upstreams** `URL | string | string[]` - It should only include the **protocol, hostname, and port**.
|
|
14
|
+
* **options** `BalancedPoolOptions` (optional)
|
|
15
|
+
|
|
16
|
+
### Parameter: `BalancedPoolOptions`
|
|
17
|
+
|
|
18
|
+
Extends: [`PoolOptions`](/docs/docs/api/Pool.md#parameter-pooloptions)
|
|
19
|
+
|
|
20
|
+
* **factory** `(origin: URL, opts: Object) => Dispatcher` - Default: `(origin, opts) => new Pool(origin, opts)`
|
|
21
|
+
|
|
22
|
+
The `PoolOptions` are passed to each of the `Pool` instances being created.
|
|
23
|
+
## Instance Properties
|
|
24
|
+
|
|
25
|
+
### `BalancedPool.upstreams`
|
|
26
|
+
|
|
27
|
+
Returns an array of upstreams that were previously added.
|
|
28
|
+
|
|
29
|
+
### `BalancedPool.closed`
|
|
30
|
+
|
|
31
|
+
Implements [Client.closed](/docs/docs/api/Client.md#clientclosed)
|
|
32
|
+
|
|
33
|
+
### `BalancedPool.destroyed`
|
|
34
|
+
|
|
35
|
+
Implements [Client.destroyed](/docs/docs/api/Client.md#clientdestroyed)
|
|
36
|
+
|
|
37
|
+
### `Pool.stats`
|
|
38
|
+
|
|
39
|
+
Returns [`PoolStats`](/docs/docs/api/PoolStats.md) instance for this pool.
|
|
40
|
+
|
|
41
|
+
## Instance Methods
|
|
42
|
+
|
|
43
|
+
### `BalancedPool.addUpstream(upstream)`
|
|
44
|
+
|
|
45
|
+
Add an upstream.
|
|
46
|
+
|
|
47
|
+
Arguments:
|
|
48
|
+
|
|
49
|
+
* **upstream** `string` - It should only include the **protocol, hostname, and port**.
|
|
50
|
+
|
|
51
|
+
### `BalancedPool.removeUpstream(upstream)`
|
|
52
|
+
|
|
53
|
+
Removes an upstream that was previously added.
|
|
54
|
+
|
|
55
|
+
### `BalancedPool.close([callback])`
|
|
56
|
+
|
|
57
|
+
Implements [`Dispatcher.close([callback])`](/docs/docs/api/Dispatcher.md#dispatcherclosecallback-promise).
|
|
58
|
+
|
|
59
|
+
### `BalancedPool.destroy([error, callback])`
|
|
60
|
+
|
|
61
|
+
Implements [`Dispatcher.destroy([error, callback])`](/docs/docs/api/Dispatcher.md#dispatcherdestroyerror-callback-promise).
|
|
62
|
+
|
|
63
|
+
### `BalancedPool.connect(options[, callback])`
|
|
64
|
+
|
|
65
|
+
See [`Dispatcher.connect(options[, callback])`](/docs/docs/api/Dispatcher.md#dispatcherconnectoptions-callback).
|
|
66
|
+
|
|
67
|
+
### `BalancedPool.dispatch(options, handlers)`
|
|
68
|
+
|
|
69
|
+
Implements [`Dispatcher.dispatch(options, handlers)`](/docs/docs/api/Dispatcher.md#dispatcherdispatchoptions-handler).
|
|
70
|
+
|
|
71
|
+
### `BalancedPool.pipeline(options, handler)`
|
|
72
|
+
|
|
73
|
+
See [`Dispatcher.pipeline(options, handler)`](/docs/docs/api/Dispatcher.md#dispatcherpipelineoptions-handler).
|
|
74
|
+
|
|
75
|
+
### `BalancedPool.request(options[, callback])`
|
|
76
|
+
|
|
77
|
+
See [`Dispatcher.request(options [, callback])`](/docs/docs/api/Dispatcher.md#dispatcherrequestoptions-callback).
|
|
78
|
+
|
|
79
|
+
### `BalancedPool.stream(options, factory[, callback])`
|
|
80
|
+
|
|
81
|
+
See [`Dispatcher.stream(options, factory[, callback])`](/docs/docs/api/Dispatcher.md#dispatcherstreamoptions-factory-callback).
|
|
82
|
+
|
|
83
|
+
### `BalancedPool.upgrade(options[, callback])`
|
|
84
|
+
|
|
85
|
+
See [`Dispatcher.upgrade(options[, callback])`](/docs/docs/api/Dispatcher.md#dispatcherupgradeoptions-callback).
|
|
86
|
+
|
|
87
|
+
## Instance Events
|
|
88
|
+
|
|
89
|
+
### Event: `'connect'`
|
|
90
|
+
|
|
91
|
+
See [Dispatcher Event: `'connect'`](/docs/docs/api/Dispatcher.md#event-connect).
|
|
92
|
+
|
|
93
|
+
### Event: `'disconnect'`
|
|
94
|
+
|
|
95
|
+
See [Dispatcher Event: `'disconnect'`](/docs/docs/api/Dispatcher.md#event-disconnect).
|
|
96
|
+
|
|
97
|
+
### Event: `'drain'`
|
|
98
|
+
|
|
99
|
+
See [Dispatcher Event: `'drain'`](/docs/docs/api/Dispatcher.md#event-drain).
|
|
@@ -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
|
+
```
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
# Cache Store
|
|
2
|
+
|
|
3
|
+
A Cache Store is responsible for storing and retrieving cached responses.
|
|
4
|
+
It is also responsible for deciding which specific response to use based off of
|
|
5
|
+
a response's `Vary` header (if present). It is expected to be compliant with
|
|
6
|
+
[RFC-9111](https://www.rfc-editor.org/rfc/rfc9111.html).
|
|
7
|
+
|
|
8
|
+
## Pre-built Cache Stores
|
|
9
|
+
|
|
10
|
+
### `MemoryCacheStore`
|
|
11
|
+
|
|
12
|
+
The `MemoryCacheStore` stores the responses in-memory.
|
|
13
|
+
|
|
14
|
+
**Options**
|
|
15
|
+
|
|
16
|
+
- `maxSize` - The maximum total size in bytes of all stored responses. Default `104857600` (100MB).
|
|
17
|
+
- `maxCount` - The maximum amount of responses to store. Default `1024`.
|
|
18
|
+
- `maxEntrySize` - The maximum size in bytes that a response's body can be. If a response's body is greater than or equal to this, the response will not be cached. Default `5242880` (5MB).
|
|
19
|
+
|
|
20
|
+
### Getters
|
|
21
|
+
|
|
22
|
+
#### `MemoryCacheStore.size`
|
|
23
|
+
|
|
24
|
+
Returns the current total size in bytes of all stored responses.
|
|
25
|
+
|
|
26
|
+
### Methods
|
|
27
|
+
|
|
28
|
+
#### `MemoryCacheStore.isFull()`
|
|
29
|
+
|
|
30
|
+
Returns a boolean indicating whether the cache has reached its maximum size or count.
|
|
31
|
+
|
|
32
|
+
### Events
|
|
33
|
+
|
|
34
|
+
#### `'maxSizeExceeded'`
|
|
35
|
+
|
|
36
|
+
Emitted when the cache exceeds its maximum size or count limits. The event payload contains `size`, `maxSize`, `count`, and `maxCount` properties.
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
### `SqliteCacheStore`
|
|
40
|
+
|
|
41
|
+
The `SqliteCacheStore` stores the responses in a SQLite database.
|
|
42
|
+
Under the hood, it uses Node.js' [`node:sqlite`](https://nodejs.org/api/sqlite.html) api.
|
|
43
|
+
The `SqliteCacheStore` is only exposed if the `node:sqlite` api is present.
|
|
44
|
+
|
|
45
|
+
**Options**
|
|
46
|
+
|
|
47
|
+
- `location` - The location of the SQLite database to use. Default `:memory:`.
|
|
48
|
+
- `maxCount` - The maximum number of entries to store in the database. Default `Infinity`.
|
|
49
|
+
- `maxEntrySize` - The maximum size in bytes that a response's body can be. If a response's body is greater than or equal to this, the response will not be cached. Default `Infinity`.
|
|
50
|
+
|
|
51
|
+
## Defining a Custom Cache Store
|
|
52
|
+
|
|
53
|
+
The store must implement the following functions:
|
|
54
|
+
|
|
55
|
+
### Getter: `isFull`
|
|
56
|
+
|
|
57
|
+
Optional. This tells the cache interceptor if the store is full or not. If this is true,
|
|
58
|
+
the cache interceptor will not attempt to cache the response.
|
|
59
|
+
|
|
60
|
+
### Function: `get`
|
|
61
|
+
|
|
62
|
+
Parameters:
|
|
63
|
+
|
|
64
|
+
* **req** `Dispatcher.RequestOptions` - Incoming request
|
|
65
|
+
|
|
66
|
+
Returns: `GetResult | Promise<GetResult | undefined> | undefined` - If the request is cached, the cached response is returned. If the request's method is anything other than HEAD, the response is also returned.
|
|
67
|
+
If the request isn't cached, `undefined` is returned.
|
|
68
|
+
|
|
69
|
+
The `get` method may return a `Promise` for async cache stores (e.g. Redis-backed or remote stores). The cache interceptor handles both synchronous and asynchronous return values, including in revalidation paths (304 Not Modified handling and stale-while-revalidate background revalidation).
|
|
70
|
+
|
|
71
|
+
Response properties:
|
|
72
|
+
|
|
73
|
+
* **response** `CacheValue` - The cached response data.
|
|
74
|
+
* **body** `Readable | Iterable<Buffer> | undefined` - The response's body. This can be an array of `Buffer` chunks (with a `.values()` method) or a `Readable` stream. Both formats are supported in all code paths, including 304 revalidation.
|
|
75
|
+
|
|
76
|
+
### Function: `createWriteStream`
|
|
77
|
+
|
|
78
|
+
Parameters:
|
|
79
|
+
|
|
80
|
+
* **req** `Dispatcher.RequestOptions` - Incoming request
|
|
81
|
+
* **value** `CacheValue` - Response to store
|
|
82
|
+
|
|
83
|
+
Returns: `Writable | undefined` - If the store is full, return `undefined`. Otherwise, return a writable so that the cache interceptor can stream the body and trailers to the store.
|
|
84
|
+
|
|
85
|
+
## `CacheValue`
|
|
86
|
+
|
|
87
|
+
This is an interface containing the majority of a response's data (minus the body).
|
|
88
|
+
|
|
89
|
+
### Property `statusCode`
|
|
90
|
+
|
|
91
|
+
`number` - The response's HTTP status code.
|
|
92
|
+
|
|
93
|
+
### Property `statusMessage`
|
|
94
|
+
|
|
95
|
+
`string` - The response's HTTP status message.
|
|
96
|
+
|
|
97
|
+
### Property `rawHeaders`
|
|
98
|
+
|
|
99
|
+
`Buffer[]` - The response's headers.
|
|
100
|
+
|
|
101
|
+
### Property `vary`
|
|
102
|
+
|
|
103
|
+
`Record<string, string | string[] | null> | undefined` - The headers defined by the response's `Vary` header
|
|
104
|
+
and their respective values for later comparison. Values are `null` when the
|
|
105
|
+
header specified in `Vary` was not present in the original request. These `null`
|
|
106
|
+
values are automatically filtered out during revalidation so they are not sent
|
|
107
|
+
as request headers.
|
|
108
|
+
|
|
109
|
+
For example, for a response like
|
|
110
|
+
```
|
|
111
|
+
Vary: content-encoding, accepts
|
|
112
|
+
content-encoding: utf8
|
|
113
|
+
accepts: application/json
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
This would be
|
|
117
|
+
```js
|
|
118
|
+
{
|
|
119
|
+
'content-encoding': 'utf8',
|
|
120
|
+
accepts: 'application/json'
|
|
121
|
+
}
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
If the original request did not include the `accepts` header:
|
|
125
|
+
```js
|
|
126
|
+
{
|
|
127
|
+
'content-encoding': 'utf8',
|
|
128
|
+
accepts: null
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Property `cachedAt`
|
|
133
|
+
|
|
134
|
+
`number` - Time in millis that this value was cached.
|
|
135
|
+
|
|
136
|
+
### Property `staleAt`
|
|
137
|
+
|
|
138
|
+
`number` - Time in millis that this value is considered stale.
|
|
139
|
+
|
|
140
|
+
### Property `deleteAt`
|
|
141
|
+
|
|
142
|
+
`number` - Time in millis that this value is to be deleted from the cache. This
|
|
143
|
+
is either the same sa staleAt or the `max-stale` caching directive.
|
|
144
|
+
|
|
145
|
+
The store must not return a response after the time defined in this property.
|
|
146
|
+
|
|
147
|
+
## `CacheStoreReadable`
|
|
148
|
+
|
|
149
|
+
This extends Node's [`Readable`](https://nodejs.org/api/stream.html#class-streamreadable)
|
|
150
|
+
and defines extra properties relevant to the cache interceptor.
|
|
151
|
+
|
|
152
|
+
### Getter: `value`
|
|
153
|
+
|
|
154
|
+
The response's [`CacheStoreValue`](/docs/docs/api/CacheStore.md#cachestorevalue)
|
|
155
|
+
|
|
156
|
+
## `CacheStoreWriteable`
|
|
157
|
+
|
|
158
|
+
This extends Node's [`Writable`](https://nodejs.org/api/stream.html#class-streamwritable)
|
|
159
|
+
and defines extra properties relevant to the cache interceptor.
|
|
160
|
+
|
|
161
|
+
### Setter: `rawTrailers`
|
|
162
|
+
|
|
163
|
+
If the response has trailers, the cache interceptor will pass them to the cache
|
|
164
|
+
interceptor through this method.
|