undici 7.0.0-alpha.7 → 7.0.0-alpha.9
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/docs/docs/api/Dispatcher.md +15 -189
- package/index.js +1 -0
- package/lib/cache/memory-cache-store.js +2 -0
- package/lib/cache/sqlite-cache-store.js +32 -43
- package/lib/core/errors.js +2 -2
- package/lib/dispatcher/dispatcher-base.js +4 -2
- package/lib/handler/cache-handler.js +148 -49
- package/lib/handler/cache-revalidation-handler.js +21 -10
- package/lib/handler/decorator-handler.js +3 -0
- package/lib/handler/redirect-handler.js +15 -38
- package/lib/handler/retry-handler.js +65 -100
- package/lib/handler/unwrap-handler.js +2 -2
- package/lib/handler/wrap-handler.js +2 -2
- package/lib/interceptor/cache.js +250 -201
- package/lib/interceptor/response-error.js +9 -5
- package/lib/util/cache.js +42 -31
- package/package.json +4 -3
- package/types/cache-interceptor.d.ts +40 -0
- package/types/dispatcher.d.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "undici",
|
|
3
|
-
"version": "7.0.0-alpha.
|
|
3
|
+
"version": "7.0.0-alpha.9",
|
|
4
4
|
"description": "An HTTP/1.1 client, written from scratch for Node.js",
|
|
5
5
|
"homepage": "https://undici.nodejs.org",
|
|
6
6
|
"bugs": {
|
|
@@ -73,6 +73,7 @@
|
|
|
73
73
|
"test:javascript:without-intl": "npm run test:javascript:no-jest",
|
|
74
74
|
"test:busboy": "borp -p \"test/busboy/*.js\"",
|
|
75
75
|
"test:cache": "borp -p \"test/cache/*.js\"",
|
|
76
|
+
"test:sqlite": "NODE_OPTIONS=--experimental-sqlite borp -p \"test/cache-interceptor/*.js\"",
|
|
76
77
|
"test:cache-interceptor": "borp -p \"test/cache-interceptor/*.js\"",
|
|
77
78
|
"test:cookies": "borp -p \"test/cookie/*.js\"",
|
|
78
79
|
"test:eventsource": "npm run build:node && borp --expose-gc -p \"test/eventsource/*.js\"",
|
|
@@ -110,7 +111,7 @@
|
|
|
110
111
|
"@sinonjs/fake-timers": "^12.0.0",
|
|
111
112
|
"@types/node": "^18.19.50",
|
|
112
113
|
"abort-controller": "^3.0.0",
|
|
113
|
-
"borp": "^0.
|
|
114
|
+
"borp": "^0.19.0",
|
|
114
115
|
"c8": "^10.0.0",
|
|
115
116
|
"cross-env": "^7.0.3",
|
|
116
117
|
"dns-packet": "^5.4.0",
|
|
@@ -128,7 +129,7 @@
|
|
|
128
129
|
"ws": "^8.11.0"
|
|
129
130
|
},
|
|
130
131
|
"engines": {
|
|
131
|
-
"node": ">=18.
|
|
132
|
+
"node": ">=20.18.1"
|
|
132
133
|
},
|
|
133
134
|
"tsd": {
|
|
134
135
|
"directory": "test/types",
|
|
@@ -7,6 +7,10 @@ declare namespace CacheHandler {
|
|
|
7
7
|
|
|
8
8
|
export interface CacheHandlerOptions {
|
|
9
9
|
store: CacheStore
|
|
10
|
+
|
|
11
|
+
cacheByDefault?: number
|
|
12
|
+
|
|
13
|
+
type?: CacheOptions['type']
|
|
10
14
|
}
|
|
11
15
|
|
|
12
16
|
export interface CacheOptions {
|
|
@@ -20,6 +24,39 @@ declare namespace CacheHandler {
|
|
|
20
24
|
* @see https://www.rfc-editor.org/rfc/rfc9110#section-9.2.1
|
|
21
25
|
*/
|
|
22
26
|
methods?: CacheMethods[]
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* RFC9111 allows for caching responses that we aren't explicitly told to
|
|
30
|
+
* cache or to not cache.
|
|
31
|
+
* @see https://www.rfc-editor.org/rfc/rfc9111.html#section-3-5
|
|
32
|
+
* @default undefined
|
|
33
|
+
*/
|
|
34
|
+
cacheByDefault?: number
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* TODO docs
|
|
38
|
+
* @default 'shared'
|
|
39
|
+
*/
|
|
40
|
+
type?: 'shared' | 'private'
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface CacheControlDirectives {
|
|
44
|
+
'max-stale'?: number;
|
|
45
|
+
'min-fresh'?: number;
|
|
46
|
+
'max-age'?: number;
|
|
47
|
+
's-maxage'?: number;
|
|
48
|
+
'stale-while-revalidate'?: number;
|
|
49
|
+
'stale-if-error'?: number;
|
|
50
|
+
public?: true;
|
|
51
|
+
private?: true | string[];
|
|
52
|
+
'no-store'?: true;
|
|
53
|
+
'no-cache'?: true | string[];
|
|
54
|
+
'must-revalidate'?: true;
|
|
55
|
+
'proxy-revalidate'?: true;
|
|
56
|
+
immutable?: true;
|
|
57
|
+
'no-transform'?: true;
|
|
58
|
+
'must-understand'?: true;
|
|
59
|
+
'only-if-cached'?: true;
|
|
23
60
|
}
|
|
24
61
|
|
|
25
62
|
export interface CacheKey {
|
|
@@ -35,6 +72,7 @@ declare namespace CacheHandler {
|
|
|
35
72
|
headers: Record<string, string | string[]>
|
|
36
73
|
vary?: Record<string, string | string[]>
|
|
37
74
|
etag?: string
|
|
75
|
+
cacheControlDirectives?: CacheControlDirectives
|
|
38
76
|
cachedAt: number
|
|
39
77
|
staleAt: number
|
|
40
78
|
deleteAt: number
|
|
@@ -50,8 +88,10 @@ declare namespace CacheHandler {
|
|
|
50
88
|
statusCode: number
|
|
51
89
|
statusMessage: string
|
|
52
90
|
headers: Record<string, string | string[]>
|
|
91
|
+
vary?: Record<string, string | string[]>
|
|
53
92
|
etag?: string
|
|
54
93
|
body: null | Readable | Iterable<Buffer> | AsyncIterable<Buffer> | Buffer | Iterable<string> | AsyncIterable<string> | string
|
|
94
|
+
cacheControlDirectives: CacheControlDirectives,
|
|
55
95
|
cachedAt: number
|
|
56
96
|
staleAt: number
|
|
57
97
|
deleteAt: number
|
package/types/dispatcher.d.ts
CHANGED
|
@@ -226,7 +226,7 @@ declare namespace Dispatcher {
|
|
|
226
226
|
export interface DispatchHandler {
|
|
227
227
|
onRequestStart?(controller: DispatchController, context: any): void;
|
|
228
228
|
onRequestUpgrade?(controller: DispatchController, statusCode: number, headers: IncomingHttpHeaders, socket: Duplex): void;
|
|
229
|
-
onResponseStart?(controller: DispatchController, statusCode: number,
|
|
229
|
+
onResponseStart?(controller: DispatchController, statusCode: number, headers: IncomingHttpHeaders, statusMessage?: string): void;
|
|
230
230
|
onResponseData?(controller: DispatchController, chunk: Buffer): void;
|
|
231
231
|
onResponseEnd?(controller: DispatchController, trailers: IncomingHttpHeaders): void;
|
|
232
232
|
onResponseError?(controller: DispatchController, error: Error): void;
|