Comparing version 4.9.5 to 4.10.0
@@ -19,5 +19,5 @@ # Agent | ||
Extends: [`ClientOptions`](docs/api/Pool.md#parameter-pooloptions) | ||
Extends: [`ClientOptions`](Pool.md#parameter-pooloptions) | ||
* **factory** `(origin: URL, opts: Object) => Dispatcher` - Default: `(origin, opts) => new Pool(origin, opts)` | ||
* **factory** `(origin: URL, opts: Object) => Dispatcher` - Default: `(origin, opts) => new Pool(origin, opts)` | ||
* **maxRedirections** `Integer` - Default: `0`. The number of HTTP redirection to follow unless otherwise specified in `DispatchOptions`. | ||
@@ -29,7 +29,7 @@ | ||
Implements [Client.closed](docs/api/Client.md#clientclosed) | ||
Implements [Client.closed](Client.md#clientclosed) | ||
### `Agent.destroyed` | ||
Implements [Client.destroyed](docs/api/Client.md#clientdestroyed) | ||
Implements [Client.destroyed](Client.md#clientdestroyed) | ||
@@ -40,15 +40,15 @@ ## Instance Methods | ||
Implements [`Dispatcher.close([callback])`](docs/api/Dispatcher.md#clientclose-callback-). | ||
Implements [`Dispatcher.close([callback])`](Dispatcher.md#dispatcherclosecallback-promise). | ||
### `Agent.destroy([error, callback])` | ||
Implements [`Dispatcher.destroy([error, callback])`](docs/api/Dispatcher.md#dispatcher-callback-). | ||
Implements [`Dispatcher.destroy([error, callback])`](Dispatcher.md#dispatcherdestroyerror-callback-promise). | ||
### `Agent.dispatch(options, handlers: AgentDispatchOptions)` | ||
### `Agent.dispatch(options, handler: AgentDispatchOptions)` | ||
Implements [`Dispatcher.dispatch(options, handlers)`](docs/api/Dispatcher.md#clientdispatchoptions-handlers). | ||
Implements [`Dispatcher.dispatch(options, handler)`](Dispatcher.md#dispatcherdispatchoptions-handler). | ||
#### Parameter: `AgentDispatchOptions` | ||
Extends: [`DispatchOptions``](docs/api/Dispatcher.md#parameter-dispatchoptions) | ||
Extends: [`DispatchOptions`](Dispatcher.md#parameter-dispatchoptions) | ||
@@ -58,26 +58,26 @@ * **origin** `string | URL` | ||
Implements [`Dispatcher.destroy([error, callback])`](docs/api/Dispatcher.md#dispatcher-callback-). | ||
Implements [`Dispatcher.destroy([error, callback])`](Dispatcher.md#dispatcherdestroyerror-callback-promise). | ||
### `Agent.connect(options[, callback])` | ||
See [`Dispatcher.connect(options[, callback])`](docs/api/Dispatcher.md#clientconnectoptions--callback). | ||
See [`Dispatcher.connect(options[, callback])`](Dispatcher.md#dispatcherconnectoptions-callback). | ||
### `Agent.dispatch(options, handlers)` | ||
### `Agent.dispatch(options, handler)` | ||
Implements [`Dispatcher.dispatch(options, handlers)`](docs/api/Dispatcher.md#clientdispatchoptions-handlers). | ||
Implements [`Dispatcher.dispatch(options, handler)`](Dispatcher.md#dispatcherdispatchoptions-handler). | ||
### `Agent.pipeline(options, handler)` | ||
See [`Dispatcher.pipeline(options, handler)`](docs/api/Dispatcher.md#clientpipelineoptions-handler). | ||
See [`Dispatcher.pipeline(options, handler)`](Dispatcher.md#dispatcherpipelineoptions-handler). | ||
### `Agent.request(options[, callback])` | ||
See [`Dispatcher.request(options [, callback])`](docs/api/Dispatcher.md#clientrequestoptions--callback). | ||
See [`Dispatcher.request(options [, callback])`](Dispatcher.md#dispatcherrequestoptions-callback). | ||
### `Agent.stream(options, factory[, callback])` | ||
See [`Dispatcher.stream(options, factory[, callback])`](docs/api/Dispatcher.md#clientstreamoptions-factory--callback). | ||
See [`Dispatcher.stream(options, factory[, callback])`](Dispatcher.md#dispatcherstreamoptions-factory-callback). | ||
### `Agent.upgrade(options[, callback])` | ||
See [`Dispatcher.upgrade(options[, callback])`](docs/api/Dispatcher.md#clientupgradeoptions-callback). | ||
See [`Dispatcher.upgrade(options[, callback])`](Dispatcher.md#dispatcherupgradeoptions-callback). |
# Client Lifecycle | ||
An Undici [Client](docs/api/Client.md) can be best described as a state machine. The following list is a summary of the various state transitions the `Client` will go through in its lifecycle. This document also contains detailed breakdowns of each state. | ||
An Undici [Client](Client.md) can be best described as a state machine. The following list is a summary of the various state transitions the `Client` will go through in its lifecycle. This document also contains detailed breakdowns of each state. | ||
@@ -32,21 +32,21 @@ > This diagram is not a perfect representation of the undici Client. Since the Client class is not actually implemented as a state-machine, actual execution may deviate slightly from what is described below. Consider this as a general resource for understanding the inner workings of the Undici client rather than some kind of formal specification. | ||
The **idle** state is the initial state of a `Client` instance. While an `origin` is required for instantiating a `Client` instance, the underlying socket connection will not be established until a request is queued using [`Client.dispatch()`](docs/api/Client.md#clientdispatchoptions-handlers). By calling `Client.dispatch()` directly or using one of the multiple implementations ([`Client.connect()`](docs/api/Client.md#clientconnectoptions--callback), [`Client.pipeline()`](docs/api/Client.md#clientpipelineoptions-handler), [`Client.request()`](docs/api/Client.md#clientrequestoptions--callback), [`Client.stream()`](docs/api/Client.md#clientstreamoptions-factory--callback), and [`Client.upgrade()`](docs/api/Client.md#clientupgradeoptions-callback)), the `Client` instance will transition from **idle** to [**pending**](#pending) and then most likely directly to [**processing**](#processing). | ||
The **idle** state is the initial state of a `Client` instance. While an `origin` is required for instantiating a `Client` instance, the underlying socket connection will not be established until a request is queued using [`Client.dispatch()`](Client.md#clientdispatchoptions-handlers). By calling `Client.dispatch()` directly or using one of the multiple implementations ([`Client.connect()`](Client.md#clientconnectoptions-callback), [`Client.pipeline()`](Client.md#clientpipelineoptions-handler), [`Client.request()`](Client.md#clientrequestoptions-callback), [`Client.stream()`](Client.md#clientstreamoptions-factory-callback), and [`Client.upgrade()`](Client.md#clientupgradeoptions-callback)), the `Client` instance will transition from **idle** to [**pending**](#pending) and then most likely directly to [**processing**](#processing). | ||
Calling [`Client.close()`](docs/api/Client.md#clientclose-callback-) or [`Client.destroy()`](docs/api/Client.md#clientdestroyerror) transitions directly to the [**destroyed**](#destroyed) state since the `Client` instance will have no queued requests in this state. | ||
Calling [`Client.close()`](Client.md#clientclosecallback) or [`Client.destroy()`](Client.md#clientdestroyerror-callback) transitions directly to the [**destroyed**](#destroyed) state since the `Client` instance will have no queued requests in this state. | ||
### pending | ||
The **pending** state signifies a non-processing `Client`. Upon entering this state, the `Client` establishes a socket connection and emits the [`'connect'`](docs/api/Client.md#event-connect) event signalling a connection was successfully established with the `origin` provided during `Client` instantiation. The internal queue is initially empty, and requests can start queueing. | ||
The **pending** state signifies a non-processing `Client`. Upon entering this state, the `Client` establishes a socket connection and emits the [`'connect'`](Client.md#event-connect) event signalling a connection was successfully established with the `origin` provided during `Client` instantiation. The internal queue is initially empty, and requests can start queueing. | ||
Calling [`Client.close()`](docs/api/Client.md#clientclose-callback-) with queued requests, transitions the `Client` to the [**processing**](#processing) state. Without queued requests, it transitions to the [**destroyed**](#destroyed) state. | ||
Calling [`Client.close()`](Client.md#clientclosecallback) with queued requests, transitions the `Client` to the [**processing**](#processing) state. Without queued requests, it transitions to the [**destroyed**](#destroyed) state. | ||
Calling [`Client.destroy()`](docs/api/Client.md#clientdestroyerror) transitions directly to the [**destroyed**](#destroyed) state regardless of existing requests. | ||
Calling [`Client.destroy()`](Client.md#clientdestroyerror-callback) transitions directly to the [**destroyed**](#destroyed) state regardless of existing requests. | ||
### processing | ||
The **processing** state is a state machine within itself. It initializes to the [**processing.running**](#running) state. The [`Client.dispatch()`](docs/api/Client.md#clientdispatchoptions-handlers), [`Client.close()`](docs/api/Client.md#clientclose-callback-), and [`Client.destroy()`](docs/api/Client.md#clientdestroyerror) can be called at any time while the `Client` is in this state. `Client.dispatch()` will add more requests to the queue while existing requests continue to be processed. `Client.close()` will transition to the [**processing.closing**](#closing) state. And `Client.destroy()` will transition to [**destroyed**](#destroyed). | ||
The **processing** state is a state machine within itself. It initializes to the [**processing.running**](#running) state. The [`Client.dispatch()`](Client.md#clientdispatchoptions-handlers), [`Client.close()`](Client.md#clientclosecallback), and [`Client.destroy()`](Client.md#clientdestroyerror-callback) can be called at any time while the `Client` is in this state. `Client.dispatch()` will add more requests to the queue while existing requests continue to be processed. `Client.close()` will transition to the [**processing.closing**](#closing) state. And `Client.destroy()` will transition to [**destroyed**](#destroyed). | ||
#### running | ||
In the **processing.running** sub-state, queued requests are being processed in a FIFO order. If a request body requires draining, the *needDrain* event transitions to the [**processing.busy**](#busy) sub-state. The *close* event transitions the Client to the [**process.closing**](#closing) sub-state. If all queued requests are processed and neither [`Client.close()`](docs/api/Client.md#clientclose-callback-) nor [`Client.destroy()`](docs/api/Client.md#clientdestroyerror) are called, then the [**processing**](#processing) machine will trigger a *keepalive* event transitioning the `Client` back to the [**pending**](#pending) state. During this time, the `Client` is waiting for the socket connection to timeout, and once it does, it triggers the *timeout* event and transitions to the [**idle**](#idle) state. | ||
In the **processing.running** sub-state, queued requests are being processed in a FIFO order. If a request body requires draining, the *needDrain* event transitions to the [**processing.busy**](#busy) sub-state. The *close* event transitions the Client to the [**process.closing**](#closing) sub-state. If all queued requests are processed and neither [`Client.close()`](Client.md#clientclosecallback) nor [`Client.destroy()`](Client.md#clientdestroyerror-callback) are called, then the [**processing**](#processing) machine will trigger a *keepalive* event transitioning the `Client` back to the [**pending**](#pending) state. During this time, the `Client` is waiting for the socket connection to timeout, and once it does, it triggers the *timeout* event and transitions to the [**idle**](#idle) state. | ||
@@ -59,3 +59,3 @@ #### busy | ||
This sub-state is only entered when a `Client` instance has queued requests and the [`Client.close()`](docs/api/Client.md#clientclose-callback-) method is called. In this state, the `Client` instance continues to process requests as usual, with the one exception that no additional requests can be queued. Once all of the queued requests are processed, the `Client` will trigger the *done* event gracefully entering the [**destroyed**](#destroyed) state without an error. | ||
This sub-state is only entered when a `Client` instance has queued requests and the [`Client.close()`](Client.md#clientclosecallback) method is called. In this state, the `Client` instance continues to process requests as usual, with the one exception that no additional requests can be queued. Once all of the queued requests are processed, the `Client` will trigger the *done* event gracefully entering the [**destroyed**](#destroyed) state without an error. | ||
@@ -62,0 +62,0 @@ ### destroyed |
@@ -5,3 +5,3 @@ # Class: BalancedPool | ||
A pool of [Pool](docs/api/Pool.md) instances connected to multiple upstreams. | ||
A pool of [Pool](Pool.md) instances connected to multiple upstreams. | ||
@@ -21,3 +21,3 @@ Requests are not guaranteed to be dispatched in order of invocation. | ||
See: [`PoolOptions`](docs/api/Pool.md#parameter-pooloptions) | ||
See: [`PoolOptions`](Pool.md#parameter-pooloptions) | ||
@@ -32,7 +32,7 @@ ## Instance Properties | ||
Implements [Client.closed](docs/api/Client.md#clientclosed) | ||
Implements [Client.closed](Client.md#clientclosed) | ||
### `BalancedPool.destroyed` | ||
Implements [Client.destroyed](docs/api/Client.md#clientdestroyed) | ||
Implements [Client.destroyed](Client.md#clientdestroyed) | ||
@@ -55,31 +55,31 @@ ## Instance Methods | ||
Implements [`Dispatcher.close([callback])`](docs/api/Dispatcher.md#clientclose-callback-). | ||
Implements [`Dispatcher.close([callback])`](Dispatcher.md#dispatcherclosecallback-promise). | ||
### `BalancedPool.destroy([error, callback])` | ||
Implements [`Dispatcher.destroy([error, callback])`](docs/api/Dispatcher.md#dispatcher-callback-). | ||
Implements [`Dispatcher.destroy([error, callback])`](Dispatcher.md#dispatcherdestroyerror-callback-promise). | ||
### `BalancedPool.connect(options[, callback])` | ||
See [`Dispatcher.connect(options[, callback])`](docs/api/Dispatcher.md#clientconnectoptions--callback). | ||
See [`Dispatcher.connect(options[, callback])`](Dispatcher.md#dispatcherconnectoptions-callback). | ||
### `BalancedPool.dispatch(options, handlers)` | ||
Implements [`Dispatcher.dispatch(options, handlers)`](docs/api/Dispatcher.md#clientdispatchoptions-handlers). | ||
Implements [`Dispatcher.dispatch(options, handlers)`](Dispatcher.md#dispatcherdispatchoptions-handler). | ||
### `BalancedPool.pipeline(options, handler)` | ||
See [`Dispatcher.pipeline(options, handler)`](docs/api/Dispatcher.md#clientpipelineoptions-handler). | ||
See [`Dispatcher.pipeline(options, handler)`](Dispatcher.md#dispatcherpipelineoptions-handler). | ||
### `BalancedPool.request(options[, callback])` | ||
See [`Dispatcher.request(options [, callback])`](docs/api/Dispatcher.md#clientrequestoptions--callback). | ||
See [`Dispatcher.request(options [, callback])`](Dispatcher.md#dispatcherrequestoptions-callback). | ||
### `BalancedPool.stream(options, factory[, callback])` | ||
See [`Dispatcher.stream(options, factory[, callback])`](docs/api/Dispatcher.md#clientstreamoptions-factory--callback). | ||
See [`Dispatcher.stream(options, factory[, callback])`](Dispatcher.md#dispatcherstreamoptions-factory-callback). | ||
### `BalancedPool.upgrade(options[, callback])` | ||
See [`Dispatcher.upgrade(options[, callback])`](docs/api/Dispatcher.md#clientupgradeoptions-callback). | ||
See [`Dispatcher.upgrade(options[, callback])`](Dispatcher.md#dispatcherupgradeoptions-callback). | ||
@@ -90,10 +90,10 @@ ## Instance Events | ||
See [Dispatcher Event: `'connect'`](docs/api/Dispatcher.md#event-connect). | ||
See [Dispatcher Event: `'connect'`](Dispatcher.md#event-connect). | ||
### Event: `'disconnect'` | ||
See [Dispatcher Event: `'disconnect'`](docs/api/Dispatcher.md#event-connect). | ||
See [Dispatcher Event: `'disconnect'`](Dispatcher.md#event-disconnect). | ||
### Event: `'drain'` | ||
See [Dispatcher Event: `'drain'`](docs/api/Dispatcher.md#event-connect). | ||
See [Dispatcher Event: `'drain'`](Dispatcher.md#event-drain). |
@@ -80,35 +80,33 @@ # Class: Client | ||
Implements [`Dispatcher.close([callback])`](docs/api/Dispatcher.md#clientclose-callback-). | ||
Implements [`Dispatcher.close([callback])`](Dispatcher.md#dispatcherclosecallback-promise). | ||
### `Client.destroy([error, callback])` | ||
Implements [`Dispatcher.destroy([error, callback])`](docs/api/Dispatcher.md#dispatcher-callback-). | ||
Implements [`Dispatcher.destroy([error, callback])`](Dispatcher.md#dispatcherdestroyerror-callback-promise). | ||
Waits until socket is closed before invoking the callback (or returning a promise if no callback is provided). | ||
Implements [`Dispatcher.destroy([error, callback])`](docs/api/Dispatcher.md#dispatcher-callback-). | ||
### `Client.connect(options[, callback])` | ||
See [`Dispatcher.connect(options[, callback])`](docs/api/Dispatcher.md#clientconnectoptions--callback). | ||
See [`Dispatcher.connect(options[, callback])`](Dispatcher.md#dispatcherconnectoptions-callback). | ||
### `Client.dispatch(options, handlers)` | ||
Implements [`Dispatcher.dispatch(options, handlers)`](docs/api/Dispatcher.md#clientdispatchoptions-handlers). | ||
Implements [`Dispatcher.dispatch(options, handlers)`](Dispatcher.md#dispatcherdispatchoptions-handler). | ||
### `Client.pipeline(options, handler)` | ||
See [`Dispatcher.pipeline(options, handler)`](docs/api/Dispatcher.md#clientpipelineoptions-handler). | ||
See [`Dispatcher.pipeline(options, handler)`](Dispatcher.md#dispatcherpipelineoptions-handler). | ||
### `Client.request(options[, callback])` | ||
See [`Dispatcher.request(options [, callback])`](docs/api/Dispatcher.md#clientrequestoptions--callback). | ||
See [`Dispatcher.request(options [, callback])`](Dispatcher.md#dispatcherrequestoptions-callback). | ||
### `Client.stream(options, factory[, callback])` | ||
See [`Dispatcher.stream(options, factory[, callback])`](docs/api/Dispatcher.md#clientstreamoptions-factory--callback). | ||
See [`Dispatcher.stream(options, factory[, callback])`](Dispatcher.md#dispatcherstreamoptions-factory-callback). | ||
### `Client.upgrade(options[, callback])` | ||
See [`Dispatcher.upgrade(options[, callback])`](docs/api/Dispatcher.md#clientupgradeoptions-callback). | ||
See [`Dispatcher.upgrade(options[, callback])`](Dispatcher.md#dispatcherupgradeoptions-callback). | ||
@@ -139,3 +137,3 @@ ## Instance Properties | ||
See [Dispatcher Event: `'connect'`](docs/api/Dispatcher.md#event-connect). | ||
See [Dispatcher Event: `'connect'`](Dispatcher.md#event-connect). | ||
@@ -186,3 +184,3 @@ Parameters: | ||
See [Dispatcher Event: `'disconnect'`](docs/api/Dispatcher.md#event-disconnect). | ||
See [Dispatcher Event: `'disconnect'`](Dispatcher.md#event-disconnect). | ||
@@ -230,5 +228,5 @@ Parameters: | ||
Emitted when pipeline is no longer [`busy`](#clientbusy). | ||
Emitted when pipeline is no longer busy. | ||
See [Dispatcher Event: `'drain'`](docs/api/Dispatcher.md#event-drain). | ||
See [Dispatcher Event: `'drain'`](Dispatcher.md#event-drain). | ||
@@ -235,0 +233,0 @@ #### Example - Client drain event |
@@ -794,7 +794,7 @@ # Dispatcher | ||
Header arguments such as `options.headers` in [`Client.dispatch`](./Client.md#client-dispatchoptions-handlers) can be specified in two forms; either as an object specified by the `http.IncomingHttpHeaders` type, or an array of strings. An array representation of a header list must have an even length or an `InvalidArgumentError` will be thrown. | ||
Header arguments such as `options.headers` in [`Client.dispatch`](Client.md#clientdispatchoptions-handlers) can be specified in two forms; either as an object specified by the `http.IncomingHttpHeaders` type, or an array of strings. An array representation of a header list must have an even length or an `InvalidArgumentError` will be thrown. | ||
Keys are lowercase and values are not modified. | ||
Response headers will derive a `host` from the `url` of the [Client](#class-client) instance if no `host` header was previously specified. | ||
Response headers will derive a `host` from the `url` of the [Client](Client.md#class-client) instance if no `host` header was previously specified. | ||
@@ -801,0 +801,0 @@ ### Example 1 - Object |
@@ -17,3 +17,3 @@ # Class: MockAgent | ||
Extends: [`AgentOptions`](docs/api/Agent.md#parameter-agentoptions) | ||
Extends: [`AgentOptions`](Agent.md#parameter-agentoptions) | ||
@@ -318,7 +318,7 @@ * **agent** `Agent` (optional) - Default: `new Agent([options])` - a custom agent encapsulated by the MockAgent. | ||
Implements [`Agent.dispatch(options, handlers)`](docs/api/Agent.md#parameter-agentdispatchoptions). | ||
Implements [`Agent.dispatch(options, handlers)`](Agent.md#parameter-agentdispatchoptions). | ||
### `MockAgent.request(options[, callback])` | ||
See [`Dispatcher.request(options [, callback])`](docs/api/Dispatcher.md#clientrequestoptions--callback). | ||
See [`Dispatcher.request(options [, callback])`](Dispatcher.md#dispatcherrequestoptions-callback). | ||
@@ -325,0 +325,0 @@ #### Example - MockAgent request |
@@ -5,3 +5,3 @@ # Class: MockClient | ||
A mock client class that implements the same api as [MockPool](docs/api/MockPool.md). | ||
A mock client class that implements the same api as [MockPool](MockPool.md). | ||
@@ -40,15 +40,15 @@ ## `new MockClient(origin, [options])` | ||
Implements: [`MockPool.intercept(options)`](docs/api/MockPool.md#mockpoolinterceptoptions) | ||
Implements: [`MockPool.intercept(options)`](MockPool.md#mockpoolinterceptoptions) | ||
### `MockClient.close()` | ||
Implements: [`MockPool.close()`](docs/api/MockPool.md#mockpoolclose) | ||
Implements: [`MockPool.close()`](MockPool.md#mockpoolclose) | ||
### `MockClient.dispatch(options, handlers)` | ||
Implements [`Dispatcher.dispatch(options, handlers)`](docs/api/Dispatcher.md#clientdispatchoptions-handlers). | ||
Implements [`Dispatcher.dispatch(options, handlers)`](Dispatcher.md#dispatcherdispatchoptions-handler). | ||
### `MockClient.request(options[, callback])` | ||
See [`Dispatcher.request(options [, callback])`](docs/api/Dispatcher.md#clientrequestoptions--callback). | ||
See [`Dispatcher.request(options [, callback])`](Dispatcher.md#dispatcherrequestoptions-callback). | ||
@@ -55,0 +55,0 @@ #### Example - MockClient request |
@@ -65,3 +65,3 @@ # Class: MockPool | ||
* **reply** `(statusCode: number, replyData: string | object, responseOptions?: MockResponseOptions) => MockScope` - define a reply for a matching request. Default for `responseOptions` is `{}`. | ||
* **reply** `(statusCode: number, replyData: string | Buffer | object, responseOptions?: MockResponseOptions) => MockScope` - define a reply for a matching request. Default for `responseOptions` is `{}`. | ||
* **replyWithError** `(error: Error) => MockScope` - define an error for a matching request to throw. | ||
@@ -72,2 +72,4 @@ * **defaultReplyHeaders** `(headers: Record<string, string>) => MockInterceptor` - define default headers to be included in subsequent replies. These are in addition to headers on a specific reply. | ||
The reply data of an intercepted request may either be a string, buffer, or JavaScript object. Objects are converted to JSON while strings and buffers are sent as-is. | ||
By default, `reply` and `replyWithError` define the behaviour for the first matching request only. Subsequent requests will not be affected (this can be changed using the returned `MockScope`). | ||
@@ -302,3 +304,3 @@ | ||
const { trailers } = await request('http://localhost:3000/foo') | ||
const { trailers } = await request('http://localhost:3000/foo') | ||
@@ -416,7 +418,7 @@ console.log('trailers', trailers) // trailers { foo: 'bar' } | ||
Implements [`Dispatcher.dispatch(options, handlers)`](docs/api/Dispatcher.md#clientdispatchoptions-handlers). | ||
Implements [`Dispatcher.dispatch(options, handlers)`](Dispatcher.md#dispatcherdispatchoptions-handler). | ||
### `MockPool.request(options[, callback])` | ||
See [`Dispatcher.request(options [, callback])`](docs/api/Dispatcher.md#clientrequestoptions--callback). | ||
See [`Dispatcher.request(options [, callback])`](Dispatcher.md#dispatcherrequestoptions-callback). | ||
@@ -423,0 +425,0 @@ #### Example - MockPool request |
@@ -5,3 +5,3 @@ # Class: Pool | ||
A pool of [Client](docs/api/Client.md) instances connected to the same upstream target. | ||
A pool of [Client](Client.md) instances connected to the same upstream target. | ||
@@ -19,3 +19,3 @@ Requests are not guaranteed to be dispatched in order of invocation. | ||
Extends: [`ClientOptions`](docs/api/Client.md#parameter-clientoptions) | ||
Extends: [`ClientOptions`](Client.md#parameter-clientoptions) | ||
@@ -29,7 +29,7 @@ * **factory** `(origin: URL, opts: Object) => Dispatcher` - Default: `(origin, opts) => new Client(origin, opts)` | ||
Implements [Client.closed](docs/api/Client.md#clientclosed) | ||
Implements [Client.closed](Client.md#clientclosed) | ||
### `Pool.destroyed` | ||
Implements [Client.destroyed](docs/api/Client.md#clientdestroyed) | ||
Implements [Client.destroyed](Client.md#clientdestroyed) | ||
@@ -40,31 +40,31 @@ ## Instance Methods | ||
Implements [`Dispatcher.close([callback])`](docs/api/Dispatcher.md#clientclose-callback-). | ||
Implements [`Dispatcher.close([callback])`](Dispatcher.md#dispatcherclosecallback-promise). | ||
### `Pool.destroy([error, callback])` | ||
Implements [`Dispatcher.destroy([error, callback])`](docs/api/Dispatcher.md#dispatcher-callback-). | ||
Implements [`Dispatcher.destroy([error, callback])`](Dispatcher.md#dispatcherdestroyerror-callback-promise). | ||
### `Pool.connect(options[, callback])` | ||
See [`Dispatcher.connect(options[, callback])`](docs/api/Dispatcher.md#clientconnectoptions--callback). | ||
See [`Dispatcher.connect(options[, callback])`](Dispatcher.md#dispatcherconnectoptions-callback). | ||
### `Pool.dispatch(options, handlers)` | ||
### `Pool.dispatch(options, handler)` | ||
Implements [`Dispatcher.dispatch(options, handlers)`](docs/api/Dispatcher.md#clientdispatchoptions-handlers). | ||
Implements [`Dispatcher.dispatch(options, handler)`](Dispatcher.md#dispatcherdispatchoptions-handler). | ||
### `Pool.pipeline(options, handler)` | ||
See [`Dispatcher.pipeline(options, handler)`](docs/api/Dispatcher.md#clientpipelineoptions-handler). | ||
See [`Dispatcher.pipeline(options, handler)`](Dispatcher.md#dispatcherpipelineoptions-handler). | ||
### `Pool.request(options[, callback])` | ||
See [`Dispatcher.request(options [, callback])`](docs/api/Dispatcher.md#clientrequestoptions--callback). | ||
See [`Dispatcher.request(options [, callback])`](Dispatcher.md#dispatcherrequestoptions-callback). | ||
### `Pool.stream(options, factory[, callback])` | ||
See [`Dispatcher.stream(options, factory[, callback])`](docs/api/Dispatcher.md#clientstreamoptions-factory--callback). | ||
See [`Dispatcher.stream(options, factory[, callback])`](Dispatcher.md#dispatcherstreamoptions-factory-callback). | ||
### `Pool.upgrade(options[, callback])` | ||
See [`Dispatcher.upgrade(options[, callback])`](docs/api/Dispatcher.md#clientupgradeoptions-callback). | ||
See [`Dispatcher.upgrade(options[, callback])`](Dispatcher.md#dispatcherupgradeoptions-callback). | ||
@@ -75,10 +75,10 @@ ## Instance Events | ||
See [Dispatcher Event: `'connect'`](docs/api/Dispatcher.md#event-connect). | ||
See [Dispatcher Event: `'connect'`](Dispatcher.md#event-connect). | ||
### Event: `'disconnect'` | ||
See [Dispatcher Event: `'disconnect'`](docs/api/Dispatcher.md#event-connect). | ||
See [Dispatcher Event: `'disconnect'`](Dispatcher.md#event-disconnect). | ||
### Event: `'drain'` | ||
See [Dispatcher Event: `'drain'`](docs/api/Dispatcher.md#event-connect). | ||
See [Dispatcher Event: `'drain'`](Dispatcher.md#event-drain). |
@@ -17,3 +17,3 @@ # Class: ProxyAgent | ||
Extends: [`AgentOptions`](docs/api/Agent.md#parameter-agentoptions) | ||
Extends: [`AgentOptions`](Agent.md#parameter-agentoptions) | ||
@@ -97,6 +97,6 @@ * **uri** `string` (required) - It can be passed either by a string or a object containing `uri` as string. | ||
Implements [`Agent.dispatch(options, handlers)`](docs/api/Agent.md#parameter-agentdispatchoptions). | ||
Implements [`Agent.dispatch(options, handlers)`](Agent.md#parameter-agentdispatchoptions). | ||
### `ProxyAgent.request(options[, callback])` | ||
See [`Dispatcher.request(options [, callback])`](docs/api/Dispatcher.md#clientrequestoptions--callback). | ||
See [`Dispatcher.request(options [, callback])`](Dispatcher.md#dispatcherrequestoptions-callback). |
@@ -6,7 +6,7 @@ 'use strict' | ||
const { File } = require('./file') | ||
const { HTMLFormElement, toUSVString } = require('./util') | ||
const { toUSVString } = require('./util') | ||
class FormData { | ||
constructor (...args) { | ||
if (args.length > 0 && !(args[0] instanceof HTMLFormElement)) { | ||
if (args.length > 0 && !(args[0]?.constructor?.name === 'HTMLFormElement')) { | ||
throw new TypeError( | ||
@@ -172,2 +172,24 @@ "Failed to construct 'FormData': parameter 1 is not of type 'HTMLFormElement'" | ||
get [Symbol.toStringTag] () { | ||
return 'FormData' | ||
} | ||
* entries () { | ||
for (const pair of this) { | ||
yield pair | ||
} | ||
} | ||
* keys () { | ||
for (const [key] of this) { | ||
yield key | ||
} | ||
} | ||
* values () { | ||
for (const [, value] of this) { | ||
yield value | ||
} | ||
} | ||
* [Symbol.iterator] () { | ||
@@ -174,0 +196,0 @@ // The value pairs to iterate over are this’s entry list’s entries with |
@@ -740,3 +740,3 @@ // https://github.com/Ethan-Arrowood/undici-fetch | ||
// terminate fetch if we have an error response. | ||
if (response.status === 0) { | ||
if (response.type === 'error') { | ||
context.terminate({ reason: response.error }) | ||
@@ -743,0 +743,0 @@ } |
@@ -232,3 +232,43 @@ 'use strict' | ||
function appendRequestOriginHeader (request) { | ||
// TODO | ||
// 1. Let serializedOrigin be the result of byte-serializing a request origin with request. | ||
let serializedOrigin = request.origin | ||
// 2. If request’s response tainting is "cors" or request’s mode is "websocket", then append (`Origin`, serializedOrigin) to request’s header list. | ||
if (request.responseTainting === 'cors' || request.mode === 'websocket') { | ||
if (serializedOrigin) { | ||
request.headersList.append('Origin', serializedOrigin) | ||
} | ||
} | ||
// 3. Otherwise, if request’s method is neither `GET` nor `HEAD`, then: | ||
else if (request.method !== 'GET' && request.method !== 'HEAD') { | ||
// 1. Switch on request’s referrer policy: | ||
switch (request.referrerPolicy) { | ||
case 'no-referrer': | ||
// Set serializedOrigin to `null`. | ||
serializedOrigin = null | ||
break | ||
case 'no-referrer-when-downgrade': | ||
case 'strict-origin': | ||
case 'strict-origin-when-cross-origin': | ||
// If request’s origin is a tuple origin, its scheme is "https", and request’s current URL’s scheme is not "https", then set serializedOrigin to `null`. | ||
if (/^https:/.test(request.origin) && !/^https:/.test(requestCurrentURL(request))) { | ||
serializedOrigin = null | ||
} | ||
break | ||
case 'same-origin': | ||
// If request’s origin is not same origin with request’s current URL’s origin, then set serializedOrigin to `null`. | ||
if (request.origin !== requestCurrentURL(request).origin) { | ||
serializedOrigin = null | ||
} | ||
break | ||
default: | ||
// Do nothing. | ||
} | ||
if (serializedOrigin) { | ||
// 2. Append (`Origin`, serializedOrigin) to request’s header list. | ||
request.headersList.append('Origin', serializedOrigin) | ||
} | ||
} | ||
} | ||
@@ -288,6 +328,4 @@ | ||
class EnvironmentSettingsObject {} // dummy | ||
class HTMLFormElement {} // dummy | ||
module.exports = { | ||
HTMLFormElement, | ||
ServiceWorkerGlobalScope, | ||
@@ -294,0 +332,0 @@ Window, |
@@ -50,3 +50,9 @@ 'use strict' | ||
function getResponseData (data) { | ||
return typeof data === 'object' ? JSON.stringify(data) : data.toString() | ||
if (Buffer.isBuffer(data)) { | ||
return data | ||
} else if (typeof data === 'object') { | ||
return JSON.stringify(data) | ||
} else { | ||
return data.toString() | ||
} | ||
} | ||
@@ -53,0 +59,0 @@ |
{ | ||
"name": "undici", | ||
"version": "4.9.5", | ||
"version": "4.10.0", | ||
"description": "An HTTP/1.1 client, written from scratch for Node.js", | ||
@@ -5,0 +5,0 @@ "homepage": "https://undici.nodejs.org", |
@@ -96,3 +96,3 @@ # undici | ||
* **options** [`RequestOptions`](./docs/api/Dispatcher.md#parameter-requestoptions) | ||
* **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcherdispatcher) | ||
* **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcher) | ||
* **method** `String` - Default: `PUT` if `options.body`, otherwise `GET` | ||
@@ -113,3 +113,3 @@ * **maxRedirections** `Integer` - Default: `0` | ||
* **options** [`StreamOptions`](./docs/api/Dispatcher.md#parameter-streamoptions) | ||
* **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcherdispatcher) | ||
* **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcher) | ||
* **method** `String` - Default: `PUT` if `options.body`, otherwise `GET` | ||
@@ -123,3 +123,3 @@ * **maxRedirections** `Integer` - Default: `0` | ||
See [Dispatcher.stream](docs/api/Dispatcher.md#dispatcherstream) for more details. | ||
See [Dispatcher.stream](docs/api/Dispatcher.md#dispatcherstreamoptions-factory-callback) for more details. | ||
@@ -132,3 +132,3 @@ ### `undici.pipeline([url, options, ]handler): Duplex` | ||
* **options** [`PipelineOptions`](docs/api/Dispatcher.md#parameter-pipelineoptions) | ||
* **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcherdispatcher) | ||
* **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcher) | ||
* **method** `String` - Default: `PUT` if `options.body`, otherwise `GET` | ||
@@ -142,3 +142,3 @@ * **maxRedirections** `Integer` - Default: `0` | ||
See [Dispatcher.pipeline](docs/api/Dispatcher.md#dispatcherpipeline) for more details. | ||
See [Dispatcher.pipeline](docs/api/Dispatcher.md#dispatcherpipelineoptions-handler) for more details. | ||
@@ -153,3 +153,3 @@ ### `undici.connect([url, options]): Promise` | ||
* **options** [`ConnectOptions`](docs/api/Dispatcher.md#parameter-connectoptions) | ||
* **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcherdispatcher) | ||
* **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcher) | ||
* **maxRedirections** `Integer` - Default: `0` | ||
@@ -162,3 +162,3 @@ * **callback** `(err: Error | null, data: ConnectData | null) => void` (optional) | ||
See [Dispatcher.connect](docs/api/Dispatcher.md#dispatcherconnect) for more details. | ||
See [Dispatcher.connect](docs/api/Dispatcher.md#dispatcherconnectoptions-callback) for more details. | ||
@@ -180,3 +180,3 @@ ### `undici.fetch(input[, init]): Promise` | ||
import {fetch} from 'undici'; | ||
async function fetchJson() { | ||
@@ -191,3 +191,3 @@ const res = await fetch('https://example.com') | ||
Nodejs has two kinds of streams: [web streams](https://nodejs.org/dist/latest-v16.x/docs/api/webstreams.html) which follow the API of the WHATWG web standard found in browsers, and an older Node-specific [streams API](https://nodejs.org/api/stream.html). `response.body` returns a readable web stream. If you would prefer to work with a Node stream you can convert a web stream using `.fromWeb()`. | ||
Nodejs has two kinds of streams: [web streams](https://nodejs.org/dist/latest-v16.x/docs/api/webstreams.html) which follow the API of the WHATWG web standard found in browsers, and an older Node-specific [streams API](https://nodejs.org/api/stream.html). `response.body` returns a readable web stream. If you would prefer to work with a Node stream you can convert a web stream using `.fromWeb()`. | ||
@@ -220,3 +220,3 @@ ```js | ||
can lead to excessive connection usage, reduced performance (due to less connection re-use), | ||
and even stalls or deadlocks when running out of connections. Therefore, it is highly | ||
and even stalls or deadlocks when running out of connections. Therefore, it is highly | ||
recommended to always either consume or cancel the response body. | ||
@@ -247,3 +247,3 @@ | ||
* **options** [`UpgradeOptions`](docs/api/Dispatcher.md#parameter-upgradeoptions) | ||
* **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcherdispatcher) | ||
* **dispatcher** `Dispatcher` - Default: [getGlobalDispatcher](#undicigetglobaldispatcher) | ||
* **maxRedirections** `Integer` - Default: `0` | ||
@@ -250,0 +250,0 @@ * **callback** `(error: Error | null, data: UpgradeData) => void` (optional) |
@@ -24,3 +24,3 @@ import { IncomingHttpHeaders } from 'http' | ||
/** Mock an undici request with the defined reply. */ | ||
reply<TData extends object = object>(statusCode: number, data: TData | string, responseOptions?: MockInterceptor.MockResponseOptions): MockScope<TData>; | ||
reply<TData extends object = object>(statusCode: number, data: TData | Buffer| string , responseOptions?: MockInterceptor.MockResponseOptions): MockScope<TData>; | ||
/** Mock an undici request by throwing the defined reply error. */ | ||
@@ -27,0 +27,0 @@ replyWithError<TError extends Error = Error>(error: TError): MockScope; |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
633664
10001
7