undici 7.0.0-alpha.3 → 7.0.0-alpha.5
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/README.md +2 -1
- package/docs/docs/api/Agent.md +14 -14
- package/docs/docs/api/BalancedPool.md +16 -16
- package/docs/docs/api/CacheStore.md +17 -14
- package/docs/docs/api/Client.md +11 -11
- package/docs/docs/api/Dispatcher.md +30 -10
- package/docs/docs/api/EnvHttpProxyAgent.md +12 -12
- package/docs/docs/api/MockAgent.md +3 -3
- package/docs/docs/api/MockClient.md +5 -5
- package/docs/docs/api/MockPool.md +2 -2
- package/docs/docs/api/Pool.md +15 -15
- package/docs/docs/api/PoolStats.md +1 -1
- package/docs/docs/api/ProxyAgent.md +3 -3
- package/docs/docs/api/RetryHandler.md +2 -2
- package/docs/docs/api/WebSocket.md +1 -1
- package/docs/docs/api/api-lifecycle.md +11 -11
- package/docs/docs/best-practices/mocking-request.md +2 -2
- package/docs/docs/best-practices/proxy.md +1 -1
- package/index.d.ts +1 -1
- package/index.js +2 -1
- package/lib/api/api-request.js +1 -1
- package/lib/cache/memory-cache-store.js +106 -342
- package/lib/core/connect.js +5 -0
- package/lib/core/request.js +2 -2
- package/lib/core/util.js +13 -40
- package/lib/dispatcher/client-h2.js +53 -33
- package/lib/handler/cache-handler.js +126 -85
- package/lib/handler/cache-revalidation-handler.js +45 -13
- package/lib/handler/redirect-handler.js +5 -3
- package/lib/handler/retry-handler.js +3 -3
- package/lib/interceptor/cache.js +213 -92
- package/lib/interceptor/dns.js +71 -48
- package/lib/util/cache.js +73 -13
- package/lib/util/timers.js +19 -1
- package/lib/web/cookies/index.js +12 -1
- package/lib/web/cookies/parse.js +6 -1
- package/lib/web/fetch/body.js +1 -5
- package/lib/web/fetch/formdata-parser.js +70 -43
- package/lib/web/fetch/headers.js +1 -1
- package/lib/web/fetch/index.js +4 -6
- package/lib/web/fetch/webidl.js +12 -4
- package/package.json +2 -3
- package/types/cache-interceptor.d.ts +51 -54
- package/types/cookies.d.ts +2 -0
- package/types/dispatcher.d.ts +1 -1
- package/types/index.d.ts +0 -1
- package/types/interceptors.d.ts +0 -1
package/README.md
CHANGED
|
@@ -402,7 +402,8 @@ Refs: https://tools.ietf.org/html/rfc7231#section-5.1.1
|
|
|
402
402
|
### Pipelining
|
|
403
403
|
|
|
404
404
|
Undici will only use pipelining if configured with a `pipelining` factor
|
|
405
|
-
greater than `1`.
|
|
405
|
+
greater than `1`. Also it is important to pass `blocking: false` to the
|
|
406
|
+
request options to properly pipeline requests.
|
|
406
407
|
|
|
407
408
|
Undici always assumes that connections are persistent and will immediately
|
|
408
409
|
pipeline requests, without checking whether the connection is persistent.
|
package/docs/docs/api/Agent.md
CHANGED
|
@@ -16,7 +16,7 @@ Returns: `Agent`
|
|
|
16
16
|
|
|
17
17
|
### Parameter: `AgentOptions`
|
|
18
18
|
|
|
19
|
-
Extends: [`PoolOptions`](Pool.md#parameter-pooloptions)
|
|
19
|
+
Extends: [`PoolOptions`](/docs/docs/api/Pool.md#parameter-pooloptions)
|
|
20
20
|
|
|
21
21
|
* **factory** `(origin: URL, opts: Object) => Dispatcher` - Default: `(origin, opts) => new Pool(origin, opts)`
|
|
22
22
|
|
|
@@ -24,54 +24,54 @@ Extends: [`PoolOptions`](Pool.md#parameter-pooloptions)
|
|
|
24
24
|
|
|
25
25
|
### `Agent.closed`
|
|
26
26
|
|
|
27
|
-
Implements [Client.closed](Client.md#clientclosed)
|
|
27
|
+
Implements [Client.closed](/docs/docs/api/Client.md#clientclosed)
|
|
28
28
|
|
|
29
29
|
### `Agent.destroyed`
|
|
30
30
|
|
|
31
|
-
Implements [Client.destroyed](Client.md#clientdestroyed)
|
|
31
|
+
Implements [Client.destroyed](/docs/docs/api/Client.md#clientdestroyed)
|
|
32
32
|
|
|
33
33
|
## Instance Methods
|
|
34
34
|
|
|
35
35
|
### `Agent.close([callback])`
|
|
36
36
|
|
|
37
|
-
Implements [`Dispatcher.close([callback])`](Dispatcher.md#dispatcherclosecallback-promise).
|
|
37
|
+
Implements [`Dispatcher.close([callback])`](/docs/docs/api/Dispatcher.md#dispatcherclosecallback-promise).
|
|
38
38
|
|
|
39
39
|
### `Agent.destroy([error, callback])`
|
|
40
40
|
|
|
41
|
-
Implements [`Dispatcher.destroy([error, callback])`](Dispatcher.md#dispatcherdestroyerror-callback-promise).
|
|
41
|
+
Implements [`Dispatcher.destroy([error, callback])`](/docs/docs/api/Dispatcher.md#dispatcherdestroyerror-callback-promise).
|
|
42
42
|
|
|
43
43
|
### `Agent.dispatch(options, handler: AgentDispatchOptions)`
|
|
44
44
|
|
|
45
|
-
Implements [`Dispatcher.dispatch(options, handler)`](Dispatcher.md#dispatcherdispatchoptions-handler).
|
|
45
|
+
Implements [`Dispatcher.dispatch(options, handler)`](/docs/docs/api/Dispatcher.md#dispatcherdispatchoptions-handler).
|
|
46
46
|
|
|
47
47
|
#### Parameter: `AgentDispatchOptions`
|
|
48
48
|
|
|
49
|
-
Extends: [`DispatchOptions`](Dispatcher.md#parameter-dispatchoptions)
|
|
49
|
+
Extends: [`DispatchOptions`](/docs/docs/api/Dispatcher.md#parameter-dispatchoptions)
|
|
50
50
|
|
|
51
51
|
* **origin** `string | URL`
|
|
52
52
|
|
|
53
|
-
Implements [`Dispatcher.destroy([error, callback])`](Dispatcher.md#dispatcherdestroyerror-callback-promise).
|
|
53
|
+
Implements [`Dispatcher.destroy([error, callback])`](/docs/docs/api/Dispatcher.md#dispatcherdestroyerror-callback-promise).
|
|
54
54
|
|
|
55
55
|
### `Agent.connect(options[, callback])`
|
|
56
56
|
|
|
57
|
-
See [`Dispatcher.connect(options[, callback])`](Dispatcher.md#dispatcherconnectoptions-callback).
|
|
57
|
+
See [`Dispatcher.connect(options[, callback])`](/docs/docs/api/Dispatcher.md#dispatcherconnectoptions-callback).
|
|
58
58
|
|
|
59
59
|
### `Agent.dispatch(options, handler)`
|
|
60
60
|
|
|
61
|
-
Implements [`Dispatcher.dispatch(options, handler)`](Dispatcher.md#dispatcherdispatchoptions-handler).
|
|
61
|
+
Implements [`Dispatcher.dispatch(options, handler)`](/docs/docs/api/Dispatcher.md#dispatcherdispatchoptions-handler).
|
|
62
62
|
|
|
63
63
|
### `Agent.pipeline(options, handler)`
|
|
64
64
|
|
|
65
|
-
See [`Dispatcher.pipeline(options, handler)`](Dispatcher.md#dispatcherpipelineoptions-handler).
|
|
65
|
+
See [`Dispatcher.pipeline(options, handler)`](/docs/docs/api/Dispatcher.md#dispatcherpipelineoptions-handler).
|
|
66
66
|
|
|
67
67
|
### `Agent.request(options[, callback])`
|
|
68
68
|
|
|
69
|
-
See [`Dispatcher.request(options [, callback])`](Dispatcher.md#dispatcherrequestoptions-callback).
|
|
69
|
+
See [`Dispatcher.request(options [, callback])`](/docs/docs/api/Dispatcher.md#dispatcherrequestoptions-callback).
|
|
70
70
|
|
|
71
71
|
### `Agent.stream(options, factory[, callback])`
|
|
72
72
|
|
|
73
|
-
See [`Dispatcher.stream(options, factory[, callback])`](Dispatcher.md#dispatcherstreamoptions-factory-callback).
|
|
73
|
+
See [`Dispatcher.stream(options, factory[, callback])`](/docs/docs/api/Dispatcher.md#dispatcherstreamoptions-factory-callback).
|
|
74
74
|
|
|
75
75
|
### `Agent.upgrade(options[, callback])`
|
|
76
76
|
|
|
77
|
-
See [`Dispatcher.upgrade(options[, callback])`](Dispatcher.md#dispatcherupgradeoptions-callback).
|
|
77
|
+
See [`Dispatcher.upgrade(options[, callback])`](/docs/docs/api/Dispatcher.md#dispatcherupgradeoptions-callback).
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Extends: `undici.Dispatcher`
|
|
4
4
|
|
|
5
|
-
A pool of [Pool](Pool.md) instances connected to multiple upstreams.
|
|
5
|
+
A pool of [Pool](/docs/docs/api/Pool.md) instances connected to multiple upstreams.
|
|
6
6
|
|
|
7
7
|
Requests are not guaranteed to be dispatched in order of invocation.
|
|
8
8
|
|
|
@@ -15,7 +15,7 @@ Arguments:
|
|
|
15
15
|
|
|
16
16
|
### Parameter: `BalancedPoolOptions`
|
|
17
17
|
|
|
18
|
-
Extends: [`PoolOptions`](Pool.md#parameter-pooloptions)
|
|
18
|
+
Extends: [`PoolOptions`](/docs/docs/api/Pool.md#parameter-pooloptions)
|
|
19
19
|
|
|
20
20
|
* **factory** `(origin: URL, opts: Object) => Dispatcher` - Default: `(origin, opts) => new Pool(origin, opts)`
|
|
21
21
|
|
|
@@ -28,15 +28,15 @@ Returns an array of upstreams that were previously added.
|
|
|
28
28
|
|
|
29
29
|
### `BalancedPool.closed`
|
|
30
30
|
|
|
31
|
-
Implements [Client.closed](Client.md#clientclosed)
|
|
31
|
+
Implements [Client.closed](/docs/docs/api/Client.md#clientclosed)
|
|
32
32
|
|
|
33
33
|
### `BalancedPool.destroyed`
|
|
34
34
|
|
|
35
|
-
Implements [Client.destroyed](Client.md#clientdestroyed)
|
|
35
|
+
Implements [Client.destroyed](/docs/docs/api/Client.md#clientdestroyed)
|
|
36
36
|
|
|
37
37
|
### `Pool.stats`
|
|
38
38
|
|
|
39
|
-
Returns [`PoolStats`](PoolStats.md) instance for this pool.
|
|
39
|
+
Returns [`PoolStats`](/docs/docs/api/PoolStats.md) instance for this pool.
|
|
40
40
|
|
|
41
41
|
## Instance Methods
|
|
42
42
|
|
|
@@ -54,46 +54,46 @@ Removes an upstream that was previously added.
|
|
|
54
54
|
|
|
55
55
|
### `BalancedPool.close([callback])`
|
|
56
56
|
|
|
57
|
-
Implements [`Dispatcher.close([callback])`](Dispatcher.md#dispatcherclosecallback-promise).
|
|
57
|
+
Implements [`Dispatcher.close([callback])`](/docs/docs/api/Dispatcher.md#dispatcherclosecallback-promise).
|
|
58
58
|
|
|
59
59
|
### `BalancedPool.destroy([error, callback])`
|
|
60
60
|
|
|
61
|
-
Implements [`Dispatcher.destroy([error, callback])`](Dispatcher.md#dispatcherdestroyerror-callback-promise).
|
|
61
|
+
Implements [`Dispatcher.destroy([error, callback])`](/docs/docs/api/Dispatcher.md#dispatcherdestroyerror-callback-promise).
|
|
62
62
|
|
|
63
63
|
### `BalancedPool.connect(options[, callback])`
|
|
64
64
|
|
|
65
|
-
See [`Dispatcher.connect(options[, callback])`](Dispatcher.md#dispatcherconnectoptions-callback).
|
|
65
|
+
See [`Dispatcher.connect(options[, callback])`](/docs/docs/api/Dispatcher.md#dispatcherconnectoptions-callback).
|
|
66
66
|
|
|
67
67
|
### `BalancedPool.dispatch(options, handlers)`
|
|
68
68
|
|
|
69
|
-
Implements [`Dispatcher.dispatch(options, handlers)`](Dispatcher.md#dispatcherdispatchoptions-handler).
|
|
69
|
+
Implements [`Dispatcher.dispatch(options, handlers)`](/docs/docs/api/Dispatcher.md#dispatcherdispatchoptions-handler).
|
|
70
70
|
|
|
71
71
|
### `BalancedPool.pipeline(options, handler)`
|
|
72
72
|
|
|
73
|
-
See [`Dispatcher.pipeline(options, handler)`](Dispatcher.md#dispatcherpipelineoptions-handler).
|
|
73
|
+
See [`Dispatcher.pipeline(options, handler)`](/docs/docs/api/Dispatcher.md#dispatcherpipelineoptions-handler).
|
|
74
74
|
|
|
75
75
|
### `BalancedPool.request(options[, callback])`
|
|
76
76
|
|
|
77
|
-
See [`Dispatcher.request(options [, callback])`](Dispatcher.md#dispatcherrequestoptions-callback).
|
|
77
|
+
See [`Dispatcher.request(options [, callback])`](/docs/docs/api/Dispatcher.md#dispatcherrequestoptions-callback).
|
|
78
78
|
|
|
79
79
|
### `BalancedPool.stream(options, factory[, callback])`
|
|
80
80
|
|
|
81
|
-
See [`Dispatcher.stream(options, factory[, callback])`](Dispatcher.md#dispatcherstreamoptions-factory-callback).
|
|
81
|
+
See [`Dispatcher.stream(options, factory[, callback])`](/docs/docs/api/Dispatcher.md#dispatcherstreamoptions-factory-callback).
|
|
82
82
|
|
|
83
83
|
### `BalancedPool.upgrade(options[, callback])`
|
|
84
84
|
|
|
85
|
-
See [`Dispatcher.upgrade(options[, callback])`](Dispatcher.md#dispatcherupgradeoptions-callback).
|
|
85
|
+
See [`Dispatcher.upgrade(options[, callback])`](/docs/docs/api/Dispatcher.md#dispatcherupgradeoptions-callback).
|
|
86
86
|
|
|
87
87
|
## Instance Events
|
|
88
88
|
|
|
89
89
|
### Event: `'connect'`
|
|
90
90
|
|
|
91
|
-
See [Dispatcher Event: `'connect'`](Dispatcher.md#event-connect).
|
|
91
|
+
See [Dispatcher Event: `'connect'`](/docs/docs/api/Dispatcher.md#event-connect).
|
|
92
92
|
|
|
93
93
|
### Event: `'disconnect'`
|
|
94
94
|
|
|
95
|
-
See [Dispatcher Event: `'disconnect'`](Dispatcher.md#event-disconnect).
|
|
95
|
+
See [Dispatcher Event: `'disconnect'`](/docs/docs/api/Dispatcher.md#event-disconnect).
|
|
96
96
|
|
|
97
97
|
### Event: `'drain'`
|
|
98
98
|
|
|
99
|
-
See [Dispatcher Event: `'drain'`](Dispatcher.md#event-drain).
|
|
99
|
+
See [Dispatcher Event: `'drain'`](/docs/docs/api/Dispatcher.md#event-drain).
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
A Cache Store is responsible for storing and retrieving cached responses.
|
|
4
4
|
It is also responsible for deciding which specific response to use based off of
|
|
5
|
-
a response's `Vary` header (if present).
|
|
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).
|
|
6
7
|
|
|
7
8
|
## Pre-built Cache Stores
|
|
8
9
|
|
|
@@ -21,27 +22,33 @@ The store must implement the following functions:
|
|
|
21
22
|
|
|
22
23
|
### Getter: `isFull`
|
|
23
24
|
|
|
24
|
-
This tells the cache interceptor if the store is full or not. If this is true,
|
|
25
|
+
Optional. This tells the cache interceptor if the store is full or not. If this is true,
|
|
25
26
|
the cache interceptor will not attempt to cache the response.
|
|
26
27
|
|
|
27
|
-
### Function: `
|
|
28
|
+
### Function: `get`
|
|
28
29
|
|
|
29
30
|
Parameters:
|
|
30
31
|
|
|
31
32
|
* **req** `Dispatcher.RequestOptions` - Incoming request
|
|
32
33
|
|
|
33
|
-
Returns: `
|
|
34
|
+
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.
|
|
35
|
+
If the request isn't cached, `undefined` is returned.
|
|
36
|
+
|
|
37
|
+
Response properties:
|
|
38
|
+
|
|
39
|
+
* **response** `CacheValue` - The cached response data.
|
|
40
|
+
* **body** `Readable | undefined` - The response's body.
|
|
34
41
|
|
|
35
42
|
### Function: `createWriteStream`
|
|
36
43
|
|
|
37
44
|
Parameters:
|
|
38
45
|
|
|
39
46
|
* **req** `Dispatcher.RequestOptions` - Incoming request
|
|
40
|
-
* **value** `
|
|
47
|
+
* **value** `CacheValue` - Response to store
|
|
41
48
|
|
|
42
|
-
Returns: `
|
|
49
|
+
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.
|
|
43
50
|
|
|
44
|
-
## `
|
|
51
|
+
## `CacheValue`
|
|
45
52
|
|
|
46
53
|
This is an interface containing the majority of a response's data (minus the body).
|
|
47
54
|
|
|
@@ -55,15 +62,11 @@ This is an interface containing the majority of a response's data (minus the bod
|
|
|
55
62
|
|
|
56
63
|
### Property `rawHeaders`
|
|
57
64
|
|
|
58
|
-
`
|
|
59
|
-
|
|
60
|
-
### Property `rawTrailers`
|
|
61
|
-
|
|
62
|
-
`string[] | undefined` - The response's trailers.
|
|
65
|
+
`Buffer[]` - The response's headers.
|
|
63
66
|
|
|
64
67
|
### Property `vary`
|
|
65
68
|
|
|
66
|
-
`Record<string, string> | undefined` - The headers defined by the response's `Vary` header
|
|
69
|
+
`Record<string, string | string[]> | undefined` - The headers defined by the response's `Vary` header
|
|
67
70
|
and their respective values for later comparison
|
|
68
71
|
|
|
69
72
|
For example, for a response like
|
|
@@ -103,7 +106,7 @@ and defines extra properties relevant to the cache interceptor.
|
|
|
103
106
|
|
|
104
107
|
### Getter: `value`
|
|
105
108
|
|
|
106
|
-
The response's [`CacheStoreValue`](#cachestorevalue)
|
|
109
|
+
The response's [`CacheStoreValue`](/docs/docs/api/CacheStore.md#cachestorevalue)
|
|
107
110
|
|
|
108
111
|
## `CacheStoreWriteable`
|
|
109
112
|
|
package/docs/docs/api/Client.md
CHANGED
|
@@ -86,37 +86,37 @@ const client = new Client('https://localhost:3000', {
|
|
|
86
86
|
|
|
87
87
|
### `Client.close([callback])`
|
|
88
88
|
|
|
89
|
-
Implements [`Dispatcher.close([callback])`](Dispatcher.md#dispatcherclosecallback-promise).
|
|
89
|
+
Implements [`Dispatcher.close([callback])`](/docs/docs/api/Dispatcher.md#dispatcherclosecallback-promise).
|
|
90
90
|
|
|
91
91
|
### `Client.destroy([error, callback])`
|
|
92
92
|
|
|
93
|
-
Implements [`Dispatcher.destroy([error, callback])`](Dispatcher.md#dispatcherdestroyerror-callback-promise).
|
|
93
|
+
Implements [`Dispatcher.destroy([error, callback])`](/docs/docs/api/Dispatcher.md#dispatcherdestroyerror-callback-promise).
|
|
94
94
|
|
|
95
95
|
Waits until socket is closed before invoking the callback (or returning a promise if no callback is provided).
|
|
96
96
|
|
|
97
97
|
### `Client.connect(options[, callback])`
|
|
98
98
|
|
|
99
|
-
See [`Dispatcher.connect(options[, callback])`](Dispatcher.md#dispatcherconnectoptions-callback).
|
|
99
|
+
See [`Dispatcher.connect(options[, callback])`](/docs/docs/api/Dispatcher.md#dispatcherconnectoptions-callback).
|
|
100
100
|
|
|
101
101
|
### `Client.dispatch(options, handlers)`
|
|
102
102
|
|
|
103
|
-
Implements [`Dispatcher.dispatch(options, handlers)`](Dispatcher.md#dispatcherdispatchoptions-handler).
|
|
103
|
+
Implements [`Dispatcher.dispatch(options, handlers)`](/docs/docs/api/Dispatcher.md#dispatcherdispatchoptions-handler).
|
|
104
104
|
|
|
105
105
|
### `Client.pipeline(options, handler)`
|
|
106
106
|
|
|
107
|
-
See [`Dispatcher.pipeline(options, handler)`](Dispatcher.md#dispatcherpipelineoptions-handler).
|
|
107
|
+
See [`Dispatcher.pipeline(options, handler)`](/docs/docs/api/Dispatcher.md#dispatcherpipelineoptions-handler).
|
|
108
108
|
|
|
109
109
|
### `Client.request(options[, callback])`
|
|
110
110
|
|
|
111
|
-
See [`Dispatcher.request(options [, callback])`](Dispatcher.md#dispatcherrequestoptions-callback).
|
|
111
|
+
See [`Dispatcher.request(options [, callback])`](/docs/docs/api/Dispatcher.md#dispatcherrequestoptions-callback).
|
|
112
112
|
|
|
113
113
|
### `Client.stream(options, factory[, callback])`
|
|
114
114
|
|
|
115
|
-
See [`Dispatcher.stream(options, factory[, callback])`](Dispatcher.md#dispatcherstreamoptions-factory-callback).
|
|
115
|
+
See [`Dispatcher.stream(options, factory[, callback])`](/docs/docs/api/Dispatcher.md#dispatcherstreamoptions-factory-callback).
|
|
116
116
|
|
|
117
117
|
### `Client.upgrade(options[, callback])`
|
|
118
118
|
|
|
119
|
-
See [`Dispatcher.upgrade(options[, callback])`](Dispatcher.md#dispatcherupgradeoptions-callback).
|
|
119
|
+
See [`Dispatcher.upgrade(options[, callback])`](/docs/docs/api/Dispatcher.md#dispatcherupgradeoptions-callback).
|
|
120
120
|
|
|
121
121
|
## Instance Properties
|
|
122
122
|
|
|
@@ -142,7 +142,7 @@ Property to get and set the pipelining factor.
|
|
|
142
142
|
|
|
143
143
|
### Event: `'connect'`
|
|
144
144
|
|
|
145
|
-
See [Dispatcher Event: `'connect'`](Dispatcher.md#event-connect).
|
|
145
|
+
See [Dispatcher Event: `'connect'`](/docs/docs/api/Dispatcher.md#event-connect).
|
|
146
146
|
|
|
147
147
|
Parameters:
|
|
148
148
|
|
|
@@ -188,7 +188,7 @@ try {
|
|
|
188
188
|
|
|
189
189
|
### Event: `'disconnect'`
|
|
190
190
|
|
|
191
|
-
See [Dispatcher Event: `'disconnect'`](Dispatcher.md#event-disconnect).
|
|
191
|
+
See [Dispatcher Event: `'disconnect'`](/docs/docs/api/Dispatcher.md#event-disconnect).
|
|
192
192
|
|
|
193
193
|
Parameters:
|
|
194
194
|
|
|
@@ -233,7 +233,7 @@ try {
|
|
|
233
233
|
|
|
234
234
|
Emitted when pipeline is no longer busy.
|
|
235
235
|
|
|
236
|
-
See [Dispatcher Event: `'drain'`](Dispatcher.md#event-drain).
|
|
236
|
+
See [Dispatcher Event: `'drain'`](/docs/docs/api/Dispatcher.md#event-drain).
|
|
237
237
|
|
|
238
238
|
#### Example - Client drain event
|
|
239
239
|
|
|
@@ -197,7 +197,7 @@ Returns: `Boolean` - `false` if dispatcher is busy and further dispatch calls wo
|
|
|
197
197
|
* **headers** `UndiciHeaders | string[]` (optional) - Default: `null`.
|
|
198
198
|
* **query** `Record<string, any> | null` (optional) - Default: `null` - Query string params to be embedded in the request URL. Note that both keys and values of query are encoded using `encodeURIComponent`. If for some reason you need to send them unencoded, embed query params into path directly instead.
|
|
199
199
|
* **idempotent** `boolean` (optional) - Default: `true` if `method` is `'HEAD'` or `'GET'` - Whether the requests can be safely retried or not. If `false` the request won't be sent until all preceding requests in the pipeline has completed.
|
|
200
|
-
* **blocking** `boolean` (optional) - Default: `
|
|
200
|
+
* **blocking** `boolean` (optional) - Default: `method !== 'HEAD'` - Whether the response is expected to take a long time and would end up blocking the pipeline. When this is set to `true` further pipelining will be avoided on the same connection until headers have been received.
|
|
201
201
|
* **upgrade** `string | null` (optional) - Default: `null` - Upgrade the request. Should be used to specify the kind of upgrade i.e. `'Websocket'`.
|
|
202
202
|
* **bodyTimeout** `number | null` (optional) - 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.
|
|
203
203
|
* **headersTimeout** `number | null` (optional) - 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.
|
|
@@ -377,7 +377,7 @@ Returns: `stream.Duplex`
|
|
|
377
377
|
|
|
378
378
|
#### Parameter: PipelineOptions
|
|
379
379
|
|
|
380
|
-
Extends: [`RequestOptions`](#parameter-requestoptions)
|
|
380
|
+
Extends: [`RequestOptions`](/docs/docs/api/Dispatcher.md#parameter-requestoptions)
|
|
381
381
|
|
|
382
382
|
* **objectMode** `boolean` (optional) - Default: `false` - Set to `true` if the `handler` will return an object stream.
|
|
383
383
|
|
|
@@ -467,7 +467,7 @@ Returns: `void | Promise<ResponseData>` - Only returns a `Promise` if no `callba
|
|
|
467
467
|
|
|
468
468
|
#### Parameter: `RequestOptions`
|
|
469
469
|
|
|
470
|
-
Extends: [`DispatchOptions`](#parameter-dispatchoptions)
|
|
470
|
+
Extends: [`DispatchOptions`](/docs/docs/api/Dispatcher.md#parameter-dispatchoptions)
|
|
471
471
|
|
|
472
472
|
* **opaque** `unknown` (optional) - Default: `null` - Used for passing through context to `ResponseData`.
|
|
473
473
|
* **signal** `AbortSignal | events.EventEmitter | null` (optional) - Default: `null`.
|
|
@@ -527,6 +527,7 @@ try {
|
|
|
527
527
|
console.log('headers', headers)
|
|
528
528
|
body.setEncoding('utf8')
|
|
529
529
|
body.on('data', console.log)
|
|
530
|
+
body.on('error', console.error)
|
|
530
531
|
body.on('end', () => {
|
|
531
532
|
console.log('trailers', trailers)
|
|
532
533
|
})
|
|
@@ -630,11 +631,30 @@ try {
|
|
|
630
631
|
}
|
|
631
632
|
```
|
|
632
633
|
|
|
634
|
+
#### Example 3 - Conditionally reading the body
|
|
635
|
+
|
|
636
|
+
Remember to fully consume the body even in the case when it is not read.
|
|
637
|
+
|
|
638
|
+
```js
|
|
639
|
+
const { body, statusCode } = await client.request({
|
|
640
|
+
path: '/',
|
|
641
|
+
method: 'GET'
|
|
642
|
+
})
|
|
643
|
+
|
|
644
|
+
if (statusCode === 200) {
|
|
645
|
+
return await body.arrayBuffer()
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
await body.dump()
|
|
649
|
+
|
|
650
|
+
return null
|
|
651
|
+
```
|
|
652
|
+
|
|
633
653
|
### `Dispatcher.stream(options, factory[, callback])`
|
|
634
654
|
|
|
635
655
|
A faster version of `Dispatcher.request`. This method expects the second argument `factory` to return a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable) stream which the response will be written to. This improves performance by avoiding creating an intermediate [`stream.Readable`](https://nodejs.org/api/stream.html#stream_readable_streams) stream when the user expects to directly pipe the response body to a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable) stream.
|
|
636
656
|
|
|
637
|
-
As demonstrated in [Example 1 - Basic GET stream request](#example-1---basic-get-stream-request), it is recommended to use the `option.opaque` property to avoid creating a closure for the `factory` method. This pattern works well with Node.js Web Frameworks such as [Fastify](https://fastify.io). See [Example 2 - Stream to Fastify Response](#example-2---stream-to-fastify-response) for more details.
|
|
657
|
+
As demonstrated in [Example 1 - Basic GET stream request](/docs/docs/api/Dispatcher.md#example-1---basic-get-stream-request), it is recommended to use the `option.opaque` property to avoid creating a closure for the `factory` method. This pattern works well with Node.js Web Frameworks such as [Fastify](https://fastify.io). See [Example 2 - Stream to Fastify Response](/docs/docs/api/Dispatch.md#example-2---stream-to-fastify-response) for more details.
|
|
638
658
|
|
|
639
659
|
Arguments:
|
|
640
660
|
|
|
@@ -916,7 +936,7 @@ await client.request({ path: '/', method: 'GET' })
|
|
|
916
936
|
|
|
917
937
|
The `redirect` interceptor allows you to customize the way your dispatcher handles redirects.
|
|
918
938
|
|
|
919
|
-
It accepts the same arguments as the [`RedirectHandler` constructor](
|
|
939
|
+
It accepts the same arguments as the [`RedirectHandler` constructor](/docs/docs/api/RedirectHandler.md).
|
|
920
940
|
|
|
921
941
|
**Example - Basic Redirect Interceptor**
|
|
922
942
|
|
|
@@ -934,7 +954,7 @@ client.request({ path: "/" })
|
|
|
934
954
|
|
|
935
955
|
The `retry` interceptor allows you to customize the way your dispatcher handles retries.
|
|
936
956
|
|
|
937
|
-
It accepts the same arguments as the [`RetryHandler` constructor](
|
|
957
|
+
It accepts the same arguments as the [`RetryHandler` constructor](/docs/docs/api/RetryHandler.md).
|
|
938
958
|
|
|
939
959
|
**Example - Basic Redirect Interceptor**
|
|
940
960
|
|
|
@@ -1001,7 +1021,7 @@ The `dns` interceptor enables you to cache DNS lookups for a given duration, per
|
|
|
1001
1021
|
- It can be either `'4` or `6`.
|
|
1002
1022
|
- It will only take effect if `dualStack` is `false`.
|
|
1003
1023
|
- `lookup: (hostname: string, options: LookupOptions, callback: (err: NodeJS.ErrnoException | null, addresses: DNSInterceptorRecord[]) => void) => void` - Custom lookup function. Default: `dns.lookup`.
|
|
1004
|
-
- For more info see [dns.lookup](https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback).
|
|
1024
|
+
- For more info see [dns.lookup](https://nodejs.org/api/dns.html#dns_dns_lookup_hostname_options_callback).
|
|
1005
1025
|
- `pick: (origin: URL, records: DNSInterceptorRecords, affinity: 4 | 6) => DNSInterceptorRecord` - Custom pick function. Default: `RoundRobin`.
|
|
1006
1026
|
- The function should return a single record from the records array.
|
|
1007
1027
|
- By default a simplified version of Round Robin is used.
|
|
@@ -1240,7 +1260,7 @@ The `cache` interceptor implements client-side response caching as described in
|
|
|
1240
1260
|
|
|
1241
1261
|
**Options**
|
|
1242
1262
|
|
|
1243
|
-
- `store` - The [`CacheStore`](
|
|
1263
|
+
- `store` - The [`CacheStore`](/docs/docs/api/CacheStore.md) to store and retrieve responses from. Default is [`MemoryCacheStore`](/docs/docs/api/CacheStore.md#memorycachestore).
|
|
1244
1264
|
- `methods` - The [**safe** HTTP methods](https://www.rfc-editor.org/rfc/rfc9110#section-9.2.1) to cache the response of.
|
|
1245
1265
|
|
|
1246
1266
|
## Instance Events
|
|
@@ -1289,13 +1309,13 @@ Emitted when dispatcher is no longer busy.
|
|
|
1289
1309
|
|
|
1290
1310
|
* `Record<string, string | string[] | undefined> | string[] | Iterable<[string, string | string[] | undefined]> | null`
|
|
1291
1311
|
|
|
1292
|
-
Header arguments such as `options.headers` in [`Client.dispatch`](Client.md#clientdispatchoptions-handlers) can be specified in three forms:
|
|
1312
|
+
Header arguments such as `options.headers` in [`Client.dispatch`](/docs/docs/api/Client.md#clientdispatchoptions-handlers) can be specified in three forms:
|
|
1293
1313
|
* As an object specified by the `Record<string, string | string[] | undefined>` (`IncomingHttpHeaders`) type.
|
|
1294
1314
|
* As an array of strings. An array representation of a header list must have an even length, or an `InvalidArgumentError` will be thrown.
|
|
1295
1315
|
* As an iterable that can encompass `Headers`, `Map`, or a custom iterator returning key-value pairs.
|
|
1296
1316
|
Keys are lowercase and values are not modified.
|
|
1297
1317
|
|
|
1298
|
-
Response headers will derive a `host` from the `url` of the [Client](Client.md#class-client) instance if no `host` header was previously specified.
|
|
1318
|
+
Response headers will derive a `host` from the `url` of the [Client](/docs/docs/api/Client.md#class-client) instance if no `host` header was previously specified.
|
|
1299
1319
|
|
|
1300
1320
|
### Example 1 - Object
|
|
1301
1321
|
|
|
@@ -20,7 +20,7 @@ Returns: `EnvHttpProxyAgent`
|
|
|
20
20
|
|
|
21
21
|
### Parameter: `EnvHttpProxyAgentOptions`
|
|
22
22
|
|
|
23
|
-
Extends: [`AgentOptions`](Agent.md#parameter-agentoptions)
|
|
23
|
+
Extends: [`AgentOptions`](/docs/docs/api/Agent.md#parameter-agentoptions)
|
|
24
24
|
|
|
25
25
|
* **httpProxy** `string` (optional) - When set, it will override the `HTTP_PROXY` environment variable.
|
|
26
26
|
* **httpsProxy** `string` (optional) - When set, it will override the `HTTPS_PROXY` environment variable.
|
|
@@ -118,44 +118,44 @@ const data = await json() // data { foo: "bar" }
|
|
|
118
118
|
|
|
119
119
|
### `EnvHttpProxyAgent.close([callback])`
|
|
120
120
|
|
|
121
|
-
Implements [`Dispatcher.close([callback])`](Dispatcher.md#dispatcherclosecallback-promise).
|
|
121
|
+
Implements [`Dispatcher.close([callback])`](/docs/docs/api/Dispatcher.md#dispatcherclosecallback-promise).
|
|
122
122
|
|
|
123
123
|
### `EnvHttpProxyAgent.destroy([error, callback])`
|
|
124
124
|
|
|
125
|
-
Implements [`Dispatcher.destroy([error, callback])`](Dispatcher.md#dispatcherdestroyerror-callback-promise).
|
|
125
|
+
Implements [`Dispatcher.destroy([error, callback])`](/docs/docs/api/Dispatcher.md#dispatcherdestroyerror-callback-promise).
|
|
126
126
|
|
|
127
127
|
### `EnvHttpProxyAgent.dispatch(options, handler: AgentDispatchOptions)`
|
|
128
128
|
|
|
129
|
-
Implements [`Dispatcher.dispatch(options, handler)`](Dispatcher.md#dispatcherdispatchoptions-handler).
|
|
129
|
+
Implements [`Dispatcher.dispatch(options, handler)`](/docs/docs/api/Dispatcher.md#dispatcherdispatchoptions-handler).
|
|
130
130
|
|
|
131
131
|
#### Parameter: `AgentDispatchOptions`
|
|
132
132
|
|
|
133
|
-
Extends: [`DispatchOptions`](Dispatcher.md#parameter-dispatchoptions)
|
|
133
|
+
Extends: [`DispatchOptions`](/docs/docs/api/Dispatcher.md#parameter-dispatchoptions)
|
|
134
134
|
|
|
135
135
|
* **origin** `string | URL`
|
|
136
136
|
|
|
137
|
-
Implements [`Dispatcher.destroy([error, callback])`](Dispatcher.md#dispatcherdestroyerror-callback-promise).
|
|
137
|
+
Implements [`Dispatcher.destroy([error, callback])`](/docs/docs/api/Dispatcher.md#dispatcherdestroyerror-callback-promise).
|
|
138
138
|
|
|
139
139
|
### `EnvHttpProxyAgent.connect(options[, callback])`
|
|
140
140
|
|
|
141
|
-
See [`Dispatcher.connect(options[, callback])`](Dispatcher.md#dispatcherconnectoptions-callback).
|
|
141
|
+
See [`Dispatcher.connect(options[, callback])`](/docs/docs/api/Dispatcher.md#dispatcherconnectoptions-callback).
|
|
142
142
|
|
|
143
143
|
### `EnvHttpProxyAgent.dispatch(options, handler)`
|
|
144
144
|
|
|
145
|
-
Implements [`Dispatcher.dispatch(options, handler)`](Dispatcher.md#dispatcherdispatchoptions-handler).
|
|
145
|
+
Implements [`Dispatcher.dispatch(options, handler)`](/docs/docs/api/Dispatcher.md#dispatcherdispatchoptions-handler).
|
|
146
146
|
|
|
147
147
|
### `EnvHttpProxyAgent.pipeline(options, handler)`
|
|
148
148
|
|
|
149
|
-
See [`Dispatcher.pipeline(options, handler)`](Dispatcher.md#dispatcherpipelineoptions-handler).
|
|
149
|
+
See [`Dispatcher.pipeline(options, handler)`](/docs/docs/api/Dispatcher.md#dispatcherpipelineoptions-handler).
|
|
150
150
|
|
|
151
151
|
### `EnvHttpProxyAgent.request(options[, callback])`
|
|
152
152
|
|
|
153
|
-
See [`Dispatcher.request(options [, callback])`](Dispatcher.md#dispatcherrequestoptions-callback).
|
|
153
|
+
See [`Dispatcher.request(options [, callback])`](/docs/docs/api/Dispatcher.md#dispatcherrequestoptions-callback).
|
|
154
154
|
|
|
155
155
|
### `EnvHttpProxyAgent.stream(options, factory[, callback])`
|
|
156
156
|
|
|
157
|
-
See [`Dispatcher.stream(options, factory[, callback])`](Dispatcher.md#dispatcherstreamoptions-factory-callback).
|
|
157
|
+
See [`Dispatcher.stream(options, factory[, callback])`](/docs/docs/api/Dispatcher.md#dispatcherstreamoptions-factory-callback).
|
|
158
158
|
|
|
159
159
|
### `EnvHttpProxyAgent.upgrade(options[, callback])`
|
|
160
160
|
|
|
161
|
-
See [`Dispatcher.upgrade(options[, callback])`](Dispatcher.md#dispatcherupgradeoptions-callback).
|
|
161
|
+
See [`Dispatcher.upgrade(options[, callback])`](/docs/docs/api/Dispatcher.md#dispatcherupgradeoptions-callback).
|
|
@@ -14,7 +14,7 @@ Returns: `MockAgent`
|
|
|
14
14
|
|
|
15
15
|
### Parameter: `MockAgentOptions`
|
|
16
16
|
|
|
17
|
-
Extends: [`AgentOptions`](Agent.md#parameter-agentoptions)
|
|
17
|
+
Extends: [`AgentOptions`](/docs/docs/api/Agent.md#parameter-agentoptions)
|
|
18
18
|
|
|
19
19
|
* **agent** `Agent` (optional) - Default: `new Agent([options])` - a custom agent encapsulated by the MockAgent.
|
|
20
20
|
|
|
@@ -301,11 +301,11 @@ await mockAgent.close()
|
|
|
301
301
|
|
|
302
302
|
### `MockAgent.dispatch(options, handlers)`
|
|
303
303
|
|
|
304
|
-
Implements [`Agent.dispatch(options, handlers)`](Agent.md#parameter-agentdispatchoptions).
|
|
304
|
+
Implements [`Agent.dispatch(options, handlers)`](/docs/docs/api/Agent.md#parameter-agentdispatchoptions).
|
|
305
305
|
|
|
306
306
|
### `MockAgent.request(options[, callback])`
|
|
307
307
|
|
|
308
|
-
See [`Dispatcher.request(options [, callback])`](Dispatcher.md#dispatcherrequestoptions-callback).
|
|
308
|
+
See [`Dispatcher.request(options [, callback])`](/docs/docs/api/Dispatcher.md#dispatcherrequestoptions-callback).
|
|
309
309
|
|
|
310
310
|
#### Example - MockAgent request
|
|
311
311
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
Extends: `undici.Client`
|
|
4
4
|
|
|
5
|
-
A mock client class that implements the same api as [MockPool](MockPool.md).
|
|
5
|
+
A mock client class that implements the same api as [MockPool](/docs/docs/api/MockPool.md).
|
|
6
6
|
|
|
7
7
|
## `new MockClient(origin, [options])`
|
|
8
8
|
|
|
@@ -36,19 +36,19 @@ const mockClient = mockAgent.get('http://localhost:3000')
|
|
|
36
36
|
|
|
37
37
|
### `MockClient.intercept(options)`
|
|
38
38
|
|
|
39
|
-
Implements: [`MockPool.intercept(options)`](MockPool.md#mockpoolinterceptoptions)
|
|
39
|
+
Implements: [`MockPool.intercept(options)`](/docs/docs/api/MockPool.md#mockpoolinterceptoptions)
|
|
40
40
|
|
|
41
41
|
### `MockClient.close()`
|
|
42
42
|
|
|
43
|
-
Implements: [`MockPool.close()`](MockPool.md#mockpoolclose)
|
|
43
|
+
Implements: [`MockPool.close()`](/docs/docs/api/MockPool.md#mockpoolclose)
|
|
44
44
|
|
|
45
45
|
### `MockClient.dispatch(options, handlers)`
|
|
46
46
|
|
|
47
|
-
Implements [`Dispatcher.dispatch(options, handlers)`](Dispatcher.md#dispatcherdispatchoptions-handler).
|
|
47
|
+
Implements [`Dispatcher.dispatch(options, handlers)`](/docs/docs/api/Dispatcher.md#dispatcherdispatchoptions-handler).
|
|
48
48
|
|
|
49
49
|
### `MockClient.request(options[, callback])`
|
|
50
50
|
|
|
51
|
-
See [`Dispatcher.request(options [, callback])`](Dispatcher.md#dispatcherrequestoptions-callback).
|
|
51
|
+
See [`Dispatcher.request(options [, callback])`](/docs/docs/api/Dispatcher.md#dispatcherrequestoptions-callback).
|
|
52
52
|
|
|
53
53
|
#### Example - MockClient request
|
|
54
54
|
|
|
@@ -512,11 +512,11 @@ await mockPool.close()
|
|
|
512
512
|
|
|
513
513
|
### `MockPool.dispatch(options, handlers)`
|
|
514
514
|
|
|
515
|
-
Implements [`Dispatcher.dispatch(options, handlers)`](Dispatcher.md#dispatcherdispatchoptions-handler).
|
|
515
|
+
Implements [`Dispatcher.dispatch(options, handlers)`](/docs/docs/api/Dispatcher.md#dispatcherdispatchoptions-handler).
|
|
516
516
|
|
|
517
517
|
### `MockPool.request(options[, callback])`
|
|
518
518
|
|
|
519
|
-
See [`Dispatcher.request(options [, callback])`](Dispatcher.md#dispatcherrequestoptions-callback).
|
|
519
|
+
See [`Dispatcher.request(options [, callback])`](/docs/docs/api/Dispatcher.md#dispatcherrequestoptions-callback).
|
|
520
520
|
|
|
521
521
|
#### Example - MockPool request
|
|
522
522
|
|