{
  "type": "module",
  "source": "doc/api/api-dispatcher.md",
  "modules": [
    {
      "textRaw": "Dispatcher",
      "name": "dispatcher",
      "introduced_in": "v4.0.0",
      "type": "module",
      "stability": 2,
      "stabilityText": "Stable",
      "desc": "<p><code>Dispatcher</code> is the core abstraction used to dispatch HTTP requests in undici.\nIt extends <a href=\"https://nodejs.org/api/events.html#class-eventemitter\"><code>EventEmitter</code></a> and defines the low-level <a href=\"#dispatcherdispatchoptions-handler\"><code>dispatch()</code></a> contract\nalong with the higher-level <a href=\"#dispatcherrequestoptions-callback\"><code>request()</code></a>, <a href=\"#dispatcherstreamoptions-factory-callback\"><code>stream()</code></a>, <a href=\"#dispatcherpipelineoptions-handler\"><code>pipeline()</code></a>,\n<a href=\"#dispatcherconnectoptions-callback\"><code>connect()</code></a>, and <a href=\"#dispatcherupgradeoptions-callback\"><code>upgrade()</code></a> methods that every concrete dispatcher\nprovides.</p>\n<p><code>Dispatcher</code> itself is abstract: its <a href=\"#dispatcherdispatchoptions-handler\"><code>dispatch()</code></a>, <a href=\"#dispatcherclosecallback\"><code>close()</code></a>, and\n<a href=\"#dispatcherdestroyerror-callback\"><code>destroy()</code></a> methods throw <code>Error: not implemented</code>. Concrete dispatchers such\nas <a href=\"Client.html#class-client\"><code>Client</code></a>, <a href=\"Pool.html#class-pool\"><code>Pool</code></a>, <a href=\"BalancedPool.html#class-balancedpool\"><code>BalancedPool</code></a>, and <a href=\"Agent.html#class-agent\"><code>Agent</code></a> implement the\ncontract and are what application code instantiates. Requests are not guaranteed\nto be dispatched in the order in which they are invoked.</p>\n<pre><code class=\"language-mjs\">import { Dispatcher, Agent } from 'undici'\n\nconst dispatcher = new Agent()\nconsole.log(dispatcher instanceof Dispatcher) // true\n</code></pre>",
      "classes": [
        {
          "textRaw": "Class: `Dispatcher`",
          "name": "Dispatcher",
          "type": "class",
          "meta": {
            "added": [
              "v4.0.0"
            ],
            "changes": []
          },
          "desc": "<ul>\n<li>Extends: <a href=\"https://nodejs.org/api/events.html#class-eventemitter\"><code>&#x3C;EventEmitter></code></a></li>\n</ul>\n<p>Base dispatcher class. Concrete dispatchers extend it and implement the\n<a href=\"#dispatcherdispatchoptions-handler\"><code>dispatch()</code></a> method on which the other request helpers are built.</p>",
          "methods": [
            {
              "textRaw": "`dispatcher.close([callback])`",
              "name": "close",
              "type": "method",
              "meta": {
                "added": [
                  "v4.0.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`callback` {Function} (optional) Invoked once the dispatcher is closed.",
                      "name": "callback",
                      "type": "Function",
                      "desc": "(optional) Invoked once the dispatcher is closed.",
                      "options": [
                        {
                          "textRaw": "`error` {Error|null}",
                          "name": "error",
                          "type": "Error|null"
                        }
                      ],
                      "optional": true
                    }
                  ],
                  "return": {
                    "textRaw": "Returns: {Promise} A `Promise` is returned only when `callback` is omitted. It resolves with `void` once the dispatcher is closed.",
                    "name": "return",
                    "type": "Promise",
                    "desc": "A `Promise` is returned only when `callback` is omitted. It resolves with `void` once the dispatcher is closed."
                  }
                }
              ],
              "desc": "<p>Closes the dispatcher and gracefully waits for enqueued requests to complete\nbefore resolving or invoking <code>callback</code>.</p>\n<pre><code class=\"language-mjs\">import { createServer } from 'node:http'\nimport { Client } from 'undici'\nimport { once } from 'node:events'\n\nconst server = createServer((request, response) => {\n  response.end('undici')\n}).listen()\n\nawait once(server, 'listening')\n\nconst client = new Client(`http://localhost:${server.address().port}`)\n\ntry {\n  const { body } = await client.request({ path: '/', method: 'GET' })\n  body.setEncoding('utf8')\n  body.on('data', console.log)\n} catch (error) {}\n\nawait client.close()\n\nconsole.log('Client closed')\nserver.close()\n</code></pre>"
            },
            {
              "textRaw": "`dispatcher.connect(options[, callback])`",
              "name": "connect",
              "type": "method",
              "meta": {
                "added": [
                  "v4.0.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`options` {Object}",
                      "name": "options",
                      "type": "Object",
                      "options": [
                        {
                          "textRaw": "`origin` {string|URL} The origin to connect to.",
                          "name": "origin",
                          "type": "string|URL",
                          "desc": "The origin to connect to."
                        },
                        {
                          "textRaw": "`path` {string} The request path.",
                          "name": "path",
                          "type": "string",
                          "desc": "The request path."
                        },
                        {
                          "textRaw": "`headers` {UndiciHeaders} Request headers. **Default:** `null`.",
                          "name": "headers",
                          "type": "UndiciHeaders",
                          "default": "`null`",
                          "desc": "Request headers."
                        },
                        {
                          "textRaw": "`signal` {AbortSignal|EventEmitter|null} A signal used to abort the request. **Default:** `null`.",
                          "name": "signal",
                          "type": "AbortSignal|EventEmitter|null",
                          "default": "`null`",
                          "desc": "A signal used to abort the request."
                        },
                        {
                          "textRaw": "`opaque` {any} An opaque value passed through to the returned `ConnectData`.",
                          "name": "opaque",
                          "type": "any",
                          "desc": "An opaque value passed through to the returned `ConnectData`."
                        },
                        {
                          "textRaw": "`responseHeaders` {string|null} Set to `'raw'` to return the response headers as a raw array instead of an object. **Default:** `null`.",
                          "name": "responseHeaders",
                          "type": "string|null",
                          "default": "`null`",
                          "desc": "Set to `'raw'` to return the response headers as a raw array instead of an object."
                        }
                      ]
                    },
                    {
                      "textRaw": "`callback` {Function} (optional) Invoked when the connection is established.",
                      "name": "callback",
                      "type": "Function",
                      "desc": "(optional) Invoked when the connection is established.",
                      "options": [
                        {
                          "textRaw": "`error` {Error|null}",
                          "name": "error",
                          "type": "Error|null"
                        },
                        {
                          "textRaw": "`data` {Object}",
                          "name": "data",
                          "type": "Object",
                          "options": [
                            {
                              "textRaw": "`statusCode` {number}",
                              "name": "statusCode",
                              "type": "number"
                            },
                            {
                              "textRaw": "`headers` {Object} The response headers.",
                              "name": "headers",
                              "type": "Object",
                              "desc": "The response headers."
                            },
                            {
                              "textRaw": "`socket` {Duplex} The established socket.",
                              "name": "socket",
                              "type": "Duplex",
                              "desc": "The established socket."
                            },
                            {
                              "textRaw": "`opaque` {any} The `opaque` value passed in `options`.",
                              "name": "opaque",
                              "type": "any",
                              "desc": "The `opaque` value passed in `options`."
                            }
                          ]
                        }
                      ],
                      "optional": true
                    }
                  ],
                  "return": {
                    "textRaw": "Returns: {Promise} A `Promise` is returned only when `callback` is omitted. It resolves with the `data` object described above.",
                    "name": "return",
                    "type": "Promise",
                    "desc": "A `Promise` is returned only when `callback` is omitted. It resolves with the `data` object described above."
                  }
                }
              ],
              "desc": "<p>Starts two-way communications with the requested resource using the\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/CONNECT\">HTTP <code>CONNECT</code></a> method.</p>\n<pre><code class=\"language-mjs\">import { createServer } from 'node:http'\nimport { Client } from 'undici'\nimport { once } from 'node:events'\n\nconst server = createServer((request, response) => {\n  throw new Error('should never get here')\n}).listen()\n\nserver.on('connect', (req, socket, head) => {\n  socket.write('HTTP/1.1 200 Connection established\\r\\n\\r\\n')\n\n  let data = head.toString()\n  socket.on('data', (buf) => {\n    data += buf.toString()\n  })\n\n  socket.on('end', () => {\n    socket.end(data)\n  })\n})\n\nawait once(server, 'listening')\n\nconst client = new Client(`http://localhost:${server.address().port}`)\n\ntry {\n  const { socket } = await client.connect({ path: '/' })\n  const wanted = 'Body'\n  let data = ''\n  socket.on('data', d => { data += d })\n  socket.on('end', () => {\n    console.log(`Data received: ${data.toString()} | Data wanted: ${wanted}`)\n    client.close()\n    server.close()\n  })\n  socket.write(wanted)\n  socket.end()\n} catch (error) {}\n</code></pre>"
            },
            {
              "textRaw": "`dispatcher.destroy([error[, callback]])`",
              "name": "destroy",
              "type": "method",
              "meta": {
                "added": [
                  "v4.0.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`error` {Error|null} (optional) The error with which pending requests are rejected. **Default:** `null`.",
                      "name": "error",
                      "type": "Error|null",
                      "default": "`null`",
                      "desc": "(optional) The error with which pending requests are rejected.",
                      "optional": true
                    },
                    {
                      "textRaw": "`callback` {Function} (optional) Invoked once the socket is closed.",
                      "name": "callback",
                      "type": "Function",
                      "desc": "(optional) Invoked once the socket is closed.",
                      "optional": true
                    }
                  ],
                  "return": {
                    "textRaw": "Returns: {Promise} A `Promise` is returned only when `callback` is omitted. It resolves with `void` once the dispatcher is destroyed.",
                    "name": "return",
                    "type": "Promise",
                    "desc": "A `Promise` is returned only when `callback` is omitted. It resolves with `void` once the dispatcher is destroyed."
                  }
                }
              ],
              "desc": "<p>Destroys the dispatcher abruptly with the given <code>error</code>. All pending and running\nrequests are asynchronously aborted and rejected. Because the operation is\ndispatched asynchronously, dispatched requests may still make some progress\nbefore being aborted.</p>\n<p>Both arguments are optional, so the method can be called in four ways:</p>\n<pre><code class=\"language-mjs\">dispatcher.destroy() // -> Promise\ndispatcher.destroy(new Error()) // -> Promise\ndispatcher.destroy(() => {}) // -> void\ndispatcher.destroy(new Error(), () => {}) // -> void\n</code></pre>\n<pre><code class=\"language-mjs\">import { createServer } from 'node:http'\nimport { Client } from 'undici'\nimport { once } from 'node:events'\n\nconst server = createServer((request, response) => {\n  response.end()\n}).listen()\n\nawait once(server, 'listening')\n\nconst client = new Client(`http://localhost:${server.address().port}`)\n\ntry {\n  const request = client.request({ path: '/', method: 'GET' })\n  client.destroy()\n    .then(() => {\n      console.log('Client destroyed')\n      server.close()\n    })\n  await request\n} catch (error) {\n  console.error(error)\n}\n</code></pre>"
            },
            {
              "textRaw": "`dispatcher.dispatch(options, handler)`",
              "name": "dispatch",
              "type": "method",
              "meta": {
                "added": [
                  "v4.0.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`options` {Object}",
                      "name": "options",
                      "type": "Object",
                      "options": [
                        {
                          "textRaw": "`origin` {string|URL} (optional) The origin to dispatch the request to.",
                          "name": "origin",
                          "type": "string|URL",
                          "desc": "(optional) The origin to dispatch the request to."
                        },
                        {
                          "textRaw": "`path` {string} The request path.",
                          "name": "path",
                          "type": "string",
                          "desc": "The request path."
                        },
                        {
                          "textRaw": "`method` {string} The HTTP method, e.g. `'GET'` or `'POST'`.",
                          "name": "method",
                          "type": "string",
                          "desc": "The HTTP method, e.g. `'GET'` or `'POST'`."
                        },
                        {
                          "textRaw": "`body` {string|Buffer|Uint8Array|Readable|FormData|null} The request body. **Default:** `null`.",
                          "name": "body",
                          "type": "string|Buffer|Uint8Array|Readable|FormData|null",
                          "default": "`null`",
                          "desc": "The request body."
                        },
                        {
                          "textRaw": "`headers` {UndiciHeaders} Request headers. **Default:** `null`.",
                          "name": "headers",
                          "type": "UndiciHeaders",
                          "default": "`null`",
                          "desc": "Request headers."
                        },
                        {
                          "textRaw": "`query` {Object} Query string parameters embedded into the request URL. Both keys and values are encoded with `encodeURIComponent`. **Default:** `null`.",
                          "name": "query",
                          "type": "Object",
                          "default": "`null`",
                          "desc": "Query string parameters embedded into the request URL. Both keys and values are encoded with `encodeURIComponent`."
                        },
                        {
                          "textRaw": "`idempotent` {boolean} Whether the request can be safely retried. If `false`, the request is not sent until all preceding requests in the pipeline have completed. **Default:** `true` when `method` is `'HEAD'` or `'GET'`.",
                          "name": "idempotent",
                          "type": "boolean",
                          "default": "`true` when `method` is `'HEAD'` or `'GET'`",
                          "desc": "Whether the request can be safely retried. If `false`, the request is not sent until all preceding requests in the pipeline have completed."
                        },
                        {
                          "textRaw": "`blocking` {boolean} Whether the response is expected to block the pipeline. When `true`, further pipelining on the same connection is avoided until headers have been received. **Default:** `method !== 'HEAD'`.",
                          "name": "blocking",
                          "type": "boolean",
                          "default": "`method !== 'HEAD'`",
                          "desc": "Whether the response is expected to block the pipeline. When `true`, further pipelining on the same connection is avoided until headers have been received."
                        },
                        {
                          "textRaw": "`typeOfService` {number|null} The IP Type of Service (ToS) value for the request socket. Must be an integer between `0` and `255`. **Default:** `0`.",
                          "name": "typeOfService",
                          "type": "number|null",
                          "default": "`0`",
                          "desc": "The IP Type of Service (ToS) value for the request socket. Must be an integer between `0` and `255`."
                        },
                        {
                          "textRaw": "`upgrade` {boolean|string|null} Upgrades the request, e.g. to `'Websocket'`. **Default:** `null`, or the request method when it is `'CONNECT'`.",
                          "name": "upgrade",
                          "type": "boolean|string|null",
                          "default": "`null`, or the request method when it is `'CONNECT'`",
                          "desc": "Upgrades the request, e.g. to `'Websocket'`."
                        },
                        {
                          "textRaw": "`headersTimeout` {number|null} The time, in milliseconds, the parser waits to receive the complete HTTP headers. Defaults to 300 seconds.",
                          "name": "headersTimeout",
                          "type": "number|null",
                          "desc": "The time, in milliseconds, the parser waits to receive the complete HTTP headers. Defaults to 300 seconds."
                        },
                        {
                          "textRaw": "`bodyTimeout` {number|null} The time, in milliseconds, after which the request times out while receiving body data. Monitors the time between body chunks. Use `0` to disable it entirely. Defaults to 300 seconds.",
                          "name": "bodyTimeout",
                          "type": "number|null",
                          "desc": "The time, in milliseconds, after which the request times out while receiving body data. Monitors the time between body chunks. Use `0` to disable it entirely. Defaults to 300 seconds."
                        },
                        {
                          "textRaw": "`reset` {boolean} Whether the request should establish a keep-alive connection. **Default:** `false`.",
                          "name": "reset",
                          "type": "boolean",
                          "default": "`false`",
                          "desc": "Whether the request should establish a keep-alive connection."
                        },
                        {
                          "textRaw": "`expectContinue` {boolean} For HTTP/2, appends the `expect: 100-continue` header and halts the request body until a `100 Continue` is received from the remote server. **Default:** `false`.",
                          "name": "expectContinue",
                          "type": "boolean",
                          "default": "`false`",
                          "desc": "For HTTP/2, appends the `expect: 100-continue` header and halts the request body until a `100 Continue` is received from the remote server."
                        }
                      ]
                    },
                    {
                      "textRaw": "`handler` {Object} A set of callbacks invoked over the request lifecycle.",
                      "name": "handler",
                      "type": "Object",
                      "desc": "A set of callbacks invoked over the request lifecycle.",
                      "options": [
                        {
                          "textRaw": "`onRequestStart` {Function} Invoked before the request is dispatched on the socket. May be invoked multiple times when the request is retried.",
                          "name": "onRequestStart",
                          "type": "Function",
                          "desc": "Invoked before the request is dispatched on the socket. May be invoked multiple times when the request is retried.",
                          "options": [
                            {
                              "textRaw": "`controller` {DispatchController}",
                              "name": "controller",
                              "type": "DispatchController"
                            },
                            {
                              "textRaw": "`context` {any}",
                              "name": "context",
                              "type": "any"
                            }
                          ]
                        },
                        {
                          "textRaw": "`onRequestUpgrade` {Function} (optional) Invoked when the request is upgraded. Required when `options.upgrade` is set or `options.method` is `'CONNECT'`.",
                          "name": "onRequestUpgrade",
                          "type": "Function",
                          "desc": "(optional) Invoked when the request is upgraded. Required when `options.upgrade` is set or `options.method` is `'CONNECT'`.",
                          "options": [
                            {
                              "textRaw": "`controller` {DispatchController}",
                              "name": "controller",
                              "type": "DispatchController"
                            },
                            {
                              "textRaw": "`statusCode` {number}",
                              "name": "statusCode",
                              "type": "number"
                            },
                            {
                              "textRaw": "`headers` {Object}",
                              "name": "headers",
                              "type": "Object"
                            },
                            {
                              "textRaw": "`socket` {Duplex}",
                              "name": "socket",
                              "type": "Duplex"
                            }
                          ]
                        },
                        {
                          "textRaw": "`onResponseStart` {Function} (optional) Invoked when the status code and headers have been received. May be invoked multiple times for 1xx informational responses. Not used for `upgrade` requests.",
                          "name": "onResponseStart",
                          "type": "Function",
                          "desc": "(optional) Invoked when the status code and headers have been received. May be invoked multiple times for 1xx informational responses. Not used for `upgrade` requests.",
                          "options": [
                            {
                              "textRaw": "`controller` {DispatchController}",
                              "name": "controller",
                              "type": "DispatchController"
                            },
                            {
                              "textRaw": "`statusCode` {number}",
                              "name": "statusCode",
                              "type": "number"
                            },
                            {
                              "textRaw": "`headers` {Object}",
                              "name": "headers",
                              "type": "Object"
                            },
                            {
                              "textRaw": "`statusMessage` {string} (optional)",
                              "name": "statusMessage",
                              "type": "string",
                              "desc": "(optional)"
                            }
                          ]
                        },
                        {
                          "textRaw": "`onResponseData` {Function} (optional) Invoked when response payload data is received. Not used for `upgrade` requests.",
                          "name": "onResponseData",
                          "type": "Function",
                          "desc": "(optional) Invoked when response payload data is received. Not used for `upgrade` requests.",
                          "options": [
                            {
                              "textRaw": "`controller` {DispatchController}",
                              "name": "controller",
                              "type": "DispatchController"
                            },
                            {
                              "textRaw": "`chunk` {Buffer}",
                              "name": "chunk",
                              "type": "Buffer"
                            }
                          ]
                        },
                        {
                          "textRaw": "`onResponseEnd` {Function} (optional) Invoked when the response payload and trailers have been received and the request has completed. Not used for `upgrade` requests.",
                          "name": "onResponseEnd",
                          "type": "Function",
                          "desc": "(optional) Invoked when the response payload and trailers have been received and the request has completed. Not used for `upgrade` requests.",
                          "options": [
                            {
                              "textRaw": "`controller` {DispatchController}",
                              "name": "controller",
                              "type": "DispatchController"
                            },
                            {
                              "textRaw": "`trailers` {Object}",
                              "name": "trailers",
                              "type": "Object"
                            }
                          ]
                        },
                        {
                          "textRaw": "`onResponseError` {Function} (optional) Invoked when an error occurs. Must not throw.",
                          "name": "onResponseError",
                          "type": "Function",
                          "desc": "(optional) Invoked when an error occurs. Must not throw.",
                          "options": [
                            {
                              "textRaw": "`controller` {DispatchController}",
                              "name": "controller",
                              "type": "DispatchController"
                            },
                            {
                              "textRaw": "`error` {Error}",
                              "name": "error",
                              "type": "Error"
                            }
                          ]
                        },
                        {
                          "textRaw": "`onResponseStarted` {Function} (optional) Invoked when the response is received, before headers have been read.",
                          "name": "onResponseStarted",
                          "type": "Function",
                          "desc": "(optional) Invoked when the response is received, before headers have been read."
                        },
                        {
                          "textRaw": "`onBodySent` {Function} (optional) Invoked when a chunk of the request body is sent. May be invoked multiple times for chunked requests.",
                          "name": "onBodySent",
                          "type": "Function",
                          "desc": "(optional) Invoked when a chunk of the request body is sent. May be invoked multiple times for chunked requests.",
                          "options": [
                            {
                              "textRaw": "`chunk` {Buffer}",
                              "name": "chunk",
                              "type": "Buffer"
                            }
                          ]
                        },
                        {
                          "textRaw": "`onRequestSent` {Function} (optional) Invoked after the request body is fully sent.",
                          "name": "onRequestSent",
                          "type": "Function",
                          "desc": "(optional) Invoked after the request body is fully sent."
                        }
                      ]
                    }
                  ],
                  "return": {
                    "textRaw": "Returns: {boolean} `false` when the dispatcher is busy and further `dispatch()` calls will make no progress until the `'drain'` event is emitted.",
                    "name": "return",
                    "type": "boolean",
                    "desc": "`false` when the dispatcher is busy and further `dispatch()` calls will make no progress until the `'drain'` event is emitted."
                  }
                }
              ],
              "desc": "<p>This is the low-level API on which all the higher-level methods are built. This\nAPI is expected to evolve through semver-major versions and is less stable than\nthe higher-level methods. It is primarily intended for library developers who\nimplement higher-level APIs on top of it.</p>\n<p>The <code>controller</code> passed to each handler is a <code>DispatchController</code> with the\nfollowing shape:</p>\n<ul>\n<li><code>aborted</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#boolean_type\"><code>&#x3C;boolean></code></a> Whether the request has been aborted.</li>\n<li><code>paused</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#boolean_type\"><code>&#x3C;boolean></code></a> Whether the request is paused.</li>\n<li><code>reason</code> <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error\"><code>&#x3C;Error></code></a> | <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#null_type\"><code>&#x3C;null></code></a> The reason the request was aborted, if any.</li>\n<li><code>rawHeaders</code> <a href=\"https://nodejs.org/api/buffer.html#class-buffer\"><code>&#x3C;Buffer></code></a>[] | <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a>[] | <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object\"><code>&#x3C;Object></code></a> | <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#null_type\"><code>&#x3C;null></code></a> The raw response headers,\npreserving duplicates and casing.</li>\n<li><code>rawTrailers</code> <a href=\"https://nodejs.org/api/buffer.html#class-buffer\"><code>&#x3C;Buffer></code></a>[] | <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#string_type\"><code>&#x3C;string></code></a>[] | <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object\"><code>&#x3C;Object></code></a> | <a href=\"https://developer.mozilla.org/docs/Web/JavaScript/Data_structures#null_type\"><code>&#x3C;null></code></a> The raw response trailers.</li>\n<li><code>abort(reason)</code> Aborts the request with the given <code>reason</code>.</li>\n<li><code>pause()</code> Pauses the response stream.</li>\n<li><code>resume()</code> Resumes the response stream.</li>\n</ul>\n<p>Call <code>controller.pause()</code> and <code>controller.resume()</code> to apply backpressure rather\nthan returning <code>false</code> from a handler.</p>\n<pre><code class=\"language-mjs\">import { createServer } from 'node:http'\nimport { Client } from 'undici'\nimport { once } from 'node:events'\n\nconst server = createServer((request, response) => {\n  response.end('Hello, World!')\n}).listen()\n\nawait once(server, 'listening')\n\nconst client = new Client(`http://localhost:${server.address().port}`)\n\nconst data = []\n\nclient.dispatch({\n  path: '/',\n  method: 'GET',\n  headers: { 'x-foo': 'bar' }\n}, {\n  onRequestStart: () => {\n    console.log('Connected!')\n  },\n  onResponseError: (_controller, error) => {\n    console.error(error)\n  },\n  onResponseStart: (_controller, statusCode, headers) => {\n    console.log(`statusCode: ${statusCode} | headers: ${JSON.stringify(headers)}`)\n  },\n  onResponseData: (_controller, chunk) => {\n    data.push(chunk)\n  },\n  onResponseEnd: (_controller, trailers) => {\n    console.log(`trailers: ${JSON.stringify(trailers)}`)\n    console.log(`Data: ${Buffer.concat(data).toString('utf8')}`)\n    client.close()\n    server.close()\n  }\n})\n</code></pre>"
            },
            {
              "textRaw": "`dispatcher.pipeline(options, handler)`",
              "name": "pipeline",
              "type": "method",
              "meta": {
                "added": [
                  "v4.0.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`options` {Object} Accepts every field of `dispatcher.request()`'s `options`, plus:",
                      "name": "options",
                      "type": "Object",
                      "desc": "Accepts every field of `dispatcher.request()`'s `options`, plus:",
                      "options": [
                        {
                          "textRaw": "`objectMode` {boolean} Set to `true` when `handler` returns an object stream. **Default:** `false`.",
                          "name": "objectMode",
                          "type": "boolean",
                          "default": "`false`",
                          "desc": "Set to `true` when `handler` returns an object stream."
                        }
                      ]
                    },
                    {
                      "textRaw": "`handler` {Function} Returns a `Readable` from which the result is read.",
                      "name": "handler",
                      "type": "Function",
                      "desc": "Returns a `Readable` from which the result is read.",
                      "options": [
                        {
                          "textRaw": "`data` {Object}",
                          "name": "data",
                          "type": "Object",
                          "options": [
                            {
                              "textRaw": "`statusCode` {number}",
                              "name": "statusCode",
                              "type": "number"
                            },
                            {
                              "textRaw": "`headers` {Object} The response headers.",
                              "name": "headers",
                              "type": "Object",
                              "desc": "The response headers."
                            },
                            {
                              "textRaw": "`opaque` {any} The `opaque` value passed in `options`.",
                              "name": "opaque",
                              "type": "any",
                              "desc": "The `opaque` value passed in `options`."
                            },
                            {
                              "textRaw": "`body` {Readable} The response body.",
                              "name": "body",
                              "type": "Readable",
                              "desc": "The response body."
                            },
                            {
                              "textRaw": "`context` {Object}",
                              "name": "context",
                              "type": "Object"
                            }
                          ]
                        },
                        {
                          "textRaw": "Returns: {Readable}",
                          "name": "return",
                          "type": "Readable"
                        }
                      ]
                    }
                  ],
                  "return": {
                    "textRaw": "Returns: {Duplex} A duplex stream that writes to the request and reads from the response.",
                    "name": "return",
                    "type": "Duplex",
                    "desc": "A duplex stream that writes to the request and reads from the response."
                  }
                }
              ],
              "desc": "<p>For easy use with <a href=\"https://nodejs.org/api/stream.html#streampipelinesource-transforms-destination-options\"><code>stream.pipeline()</code></a>. The <code>handler</code> should return a\n<code>Readable</code> from which the result is read. Usually it returns the <code>body</code> directly,\nunless a transformation is needed based on, for example, <code>headers</code> or\n<code>statusCode</code>. The <code>handler</code> should validate the response and save any required\nstate; if there is an error, it should be thrown.</p>\n<pre><code class=\"language-mjs\">import { Readable, Writable, PassThrough, pipeline } from 'node:stream'\nimport { createServer } from 'node:http'\nimport { Client } from 'undici'\nimport { once } from 'node:events'\n\nconst server = createServer((request, response) => {\n  request.pipe(response)\n}).listen()\n\nawait once(server, 'listening')\n\nconst client = new Client(`http://localhost:${server.address().port}`)\n\nlet res = ''\n\npipeline(\n  new Readable({\n    read () {\n      this.push(Buffer.from('undici'))\n      this.push(null)\n    }\n  }),\n  client.pipeline({ path: '/', method: 'GET' }, ({ statusCode, headers, body }) => {\n    console.log(`response received ${statusCode}`)\n    console.log('headers', headers)\n    return pipeline(body, new PassThrough(), () => {})\n  }),\n  new Writable({\n    write (chunk, _, callback) {\n      res += chunk.toString()\n      callback()\n    },\n    final (callback) {\n      console.log(`Response pipelined to writable: ${res}`)\n      callback()\n    }\n  }),\n  error => {\n    if (error) {\n      console.error(error)\n    }\n    client.close()\n    server.close()\n  }\n)\n</code></pre>"
            },
            {
              "textRaw": "`dispatcher.request(options[, callback])`",
              "name": "request",
              "type": "method",
              "meta": {
                "added": [
                  "v4.0.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`options` {Object} Accepts every field of `dispatcher.dispatch()`'s `options`, plus:",
                      "name": "options",
                      "type": "Object",
                      "desc": "Accepts every field of `dispatcher.dispatch()`'s `options`, plus:",
                      "options": [
                        {
                          "textRaw": "`opaque` {any} A value passed through to the returned response data. **Default:** `null`.",
                          "name": "opaque",
                          "type": "any",
                          "default": "`null`",
                          "desc": "A value passed through to the returned response data."
                        },
                        {
                          "textRaw": "`signal` {AbortSignal|EventEmitter|null} A signal used to abort the request. **Default:** `null`.",
                          "name": "signal",
                          "type": "AbortSignal|EventEmitter|null",
                          "default": "`null`",
                          "desc": "A signal used to abort the request."
                        },
                        {
                          "textRaw": "`onInfo` {Function|null} Invoked for each informational (1xx) response received. **Default:** `null`.",
                          "name": "onInfo",
                          "type": "Function|null",
                          "default": "`null`",
                          "desc": "Invoked for each informational (1xx) response received.",
                          "options": [
                            {
                              "textRaw": "`info` {Object}",
                              "name": "info",
                              "type": "Object",
                              "options": [
                                {
                                  "textRaw": "`statusCode` {number}",
                                  "name": "statusCode",
                                  "type": "number"
                                },
                                {
                                  "textRaw": "`headers` {Object}",
                                  "name": "headers",
                                  "type": "Object"
                                }
                              ]
                            }
                          ]
                        },
                        {
                          "textRaw": "`responseHeaders` {string|null} Set to `'raw'` to return the response headers as a raw array. **Default:** `null`.",
                          "name": "responseHeaders",
                          "type": "string|null",
                          "default": "`null`",
                          "desc": "Set to `'raw'` to return the response headers as a raw array."
                        },
                        {
                          "textRaw": "`highWaterMark` {number} The high water mark of the response body stream. **Default:** `65536` (64 KiB).",
                          "name": "highWaterMark",
                          "type": "number",
                          "default": "`65536` (64 KiB)",
                          "desc": "The high water mark of the response body stream."
                        }
                      ]
                    },
                    {
                      "textRaw": "`callback` {Function} (optional) Invoked when the response is received.",
                      "name": "callback",
                      "type": "Function",
                      "desc": "(optional) Invoked when the response is received.",
                      "options": [
                        {
                          "textRaw": "`error` {Error|null}",
                          "name": "error",
                          "type": "Error|null"
                        },
                        {
                          "textRaw": "`data` {Object}",
                          "name": "data",
                          "type": "Object",
                          "options": [
                            {
                              "textRaw": "`statusCode` {number}",
                              "name": "statusCode",
                              "type": "number"
                            },
                            {
                              "textRaw": "`statusText` {string} The status message, e.g. `'OK'` or `'Not Found'`.",
                              "name": "statusText",
                              "type": "string",
                              "desc": "The status message, e.g. `'OK'` or `'Not Found'`."
                            },
                            {
                              "textRaw": "`headers` {Object} The response headers. All keys are lower-cased.",
                              "name": "headers",
                              "type": "Object",
                              "desc": "The response headers. All keys are lower-cased."
                            },
                            {
                              "textRaw": "`body` {Readable} The response body, which also implements the body mixin from the Fetch Standard.",
                              "name": "body",
                              "type": "Readable",
                              "desc": "The response body, which also implements the body mixin from the Fetch Standard."
                            },
                            {
                              "textRaw": "`trailers` {Object} Starts out empty and is mutated to contain the trailers after `body` emits `'end'`.",
                              "name": "trailers",
                              "type": "Object",
                              "desc": "Starts out empty and is mutated to contain the trailers after `body` emits `'end'`."
                            },
                            {
                              "textRaw": "`opaque` {any} The `opaque` value passed in `options`.",
                              "name": "opaque",
                              "type": "any",
                              "desc": "The `opaque` value passed in `options`."
                            },
                            {
                              "textRaw": "`context` {Object}",
                              "name": "context",
                              "type": "Object"
                            }
                          ]
                        }
                      ],
                      "optional": true
                    }
                  ],
                  "return": {
                    "textRaw": "Returns: {Promise} A `Promise` is returned only when `callback` is omitted. It resolves with the `data` object described above.",
                    "name": "return",
                    "type": "Promise",
                    "desc": "A `Promise` is returned only when `callback` is omitted. It resolves with the `data` object described above."
                  }
                }
              ],
              "desc": "<p>Performs an HTTP request. <code>options.method</code> must not be <code>'CONNECT'</code>.</p>\n<p>Non-idempotent requests are not pipelined, to avoid indirect failures. Idempotent\nrequests are automatically retried if they fail due to an indirect failure from\nthe request at the head of the pipeline; this does not apply to idempotent\nrequests with a stream request body. All response bodies must always be fully\nconsumed or destroyed.</p>\n<p>The <code>body</code> exposes the following <a href=\"https://fetch.spec.whatwg.org/#body-mixin\">body mixin</a> methods and properties:\n<a href=\"https://fetch.spec.whatwg.org/#dom-body-arraybuffer\"><code>.arrayBuffer()</code></a>, <a href=\"https://fetch.spec.whatwg.org/#dom-body-blob\"><code>.blob()</code></a>, <a href=\"https://fetch.spec.whatwg.org/#dom-body-bytes\"><code>.bytes()</code></a>, <a href=\"https://fetch.spec.whatwg.org/#dom-body-json\"><code>.json()</code></a>,\n<a href=\"https://fetch.spec.whatwg.org/#dom-body-text\"><code>.text()</code></a>, <code>body</code>, and <code>bodyUsed</code>. A body cannot be consumed twice; for\nexample, calling <code>text()</code> after <code>json()</code> throws a <code>TypeError</code>. The body also\nprovides <code>dump({ limit })</code>, which discards up to <code>limit</code> bytes (default\n<code>131072</code>) without destroying the socket.</p>\n<p>The body is always a <code>Readable</code>, even when empty. Deserializing an empty body\nwith <code>json()</code> throws. To guard against this, verify the status code is not <code>204</code>\nand the <code>content-type</code> header starts with <code>application/json</code> before calling\n<code>json()</code>.</p>\n<pre><code class=\"language-mjs\">import { createServer } from 'node:http'\nimport { Client } from 'undici'\nimport { once } from 'node:events'\n\nconst server = createServer((request, response) => {\n  response.end('Hello, World!')\n}).listen()\n\nawait once(server, 'listening')\n\nconst client = new Client(`http://localhost:${server.address().port}`)\n\ntry {\n  const { body, headers, statusCode, statusText, trailers } = await client.request({\n    path: '/',\n    method: 'GET'\n  })\n  console.log(`response received ${statusCode}`)\n  console.log('headers', headers)\n  body.setEncoding('utf8')\n  body.on('data', console.log)\n  body.on('error', console.error)\n  body.on('end', () => {\n    console.log('trailers', trailers)\n  })\n\n  client.close()\n  server.close()\n} catch (error) {\n  console.error(error)\n}\n</code></pre>\n<p>A request can be aborted with an <code>AbortSignal</code>, with any <code>EventEmitter</code> that\nemits an <code>'abort'</code> event, or by destroying the response body:</p>\n<pre><code class=\"language-mjs\">import { Client } from 'undici'\n\nconst client = new Client('http://localhost:3000')\nconst abortController = new AbortController()\n\ntry {\n  client.request({ path: '/', method: 'GET', signal: abortController.signal })\n} catch (error) {\n  console.error(error) // RequestAbortedError\n}\n\nabortController.abort()\n</code></pre>\n<p>When the response body is conditionally read, always fully consume it otherwise:</p>\n<pre><code class=\"language-mjs\">const { body, statusCode } = await client.request({ path: '/', method: 'GET' })\n\nif (statusCode === 200) {\n  return await body.arrayBuffer()\n}\n\nawait body.dump()\n\nreturn null\n</code></pre>"
            },
            {
              "textRaw": "`dispatcher.stream(options, factory[, callback])`",
              "name": "stream",
              "type": "method",
              "meta": {
                "added": [
                  "v4.0.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`options` {Object} Accepts the same fields as `dispatcher.request()`'s `options`.",
                      "name": "options",
                      "type": "Object",
                      "desc": "Accepts the same fields as `dispatcher.request()`'s `options`."
                    },
                    {
                      "textRaw": "`factory` {Function} Returns the `Writable` to which the response is written.",
                      "name": "factory",
                      "type": "Function",
                      "desc": "Returns the `Writable` to which the response is written.",
                      "options": [
                        {
                          "textRaw": "`data` {Object}",
                          "name": "data",
                          "type": "Object",
                          "options": [
                            {
                              "textRaw": "`statusCode` {number}",
                              "name": "statusCode",
                              "type": "number"
                            },
                            {
                              "textRaw": "`headers` {Object} The response headers.",
                              "name": "headers",
                              "type": "Object",
                              "desc": "The response headers."
                            },
                            {
                              "textRaw": "`opaque` {any} The `opaque` value passed in `options`.",
                              "name": "opaque",
                              "type": "any",
                              "desc": "The `opaque` value passed in `options`."
                            },
                            {
                              "textRaw": "`context` {Object}",
                              "name": "context",
                              "type": "Object"
                            }
                          ]
                        },
                        {
                          "textRaw": "Returns: {Writable}",
                          "name": "return",
                          "type": "Writable"
                        }
                      ]
                    },
                    {
                      "textRaw": "`callback` {Function} (optional) Invoked when the request has completed.",
                      "name": "callback",
                      "type": "Function",
                      "desc": "(optional) Invoked when the request has completed.",
                      "options": [
                        {
                          "textRaw": "`error` {Error|null}",
                          "name": "error",
                          "type": "Error|null"
                        },
                        {
                          "textRaw": "`data` {Object}",
                          "name": "data",
                          "type": "Object",
                          "options": [
                            {
                              "textRaw": "`opaque` {any} The `opaque` value passed in `options`.",
                              "name": "opaque",
                              "type": "any",
                              "desc": "The `opaque` value passed in `options`."
                            },
                            {
                              "textRaw": "`trailers` {Object}",
                              "name": "trailers",
                              "type": "Object"
                            }
                          ]
                        }
                      ],
                      "optional": true
                    }
                  ],
                  "return": {
                    "textRaw": "Returns: {Promise} A `Promise` is returned only when `callback` is omitted. It resolves with the `data` object described above.",
                    "name": "return",
                    "type": "Promise",
                    "desc": "A `Promise` is returned only when `callback` is omitted. It resolves with the `data` object described above."
                  }
                }
              ],
              "desc": "<p>A faster version of <a href=\"#dispatcherrequestoptions-callback\"><code>dispatcher.request()</code></a>. The <code>factory</code> returns a\n<a href=\"https://nodejs.org/api/stream.html#class-streamwritable\"><code>Writable</code></a> to which the response is written, which avoids creating an\nintermediate <a href=\"https://nodejs.org/api/stream.html#class-streamreadable\"><code>Readable</code></a> when the caller intends to pipe the response body\ndirectly to a <code>Writable</code>.</p>\n<p>Use <code>options.opaque</code> to avoid creating a closure for the <code>factory</code> method. This\npattern works well with Node.js web frameworks such as <a href=\"https://fastify.dev\">Fastify</a>.</p>\n<pre><code class=\"language-mjs\">import { createServer } from 'node:http'\nimport { Client } from 'undici'\nimport { once } from 'node:events'\nimport { Writable } from 'node:stream'\n\nconst server = createServer((request, response) => {\n  response.end('Hello, World!')\n}).listen()\n\nawait once(server, 'listening')\n\nconst client = new Client(`http://localhost:${server.address().port}`)\n\nconst bufs = []\n\ntry {\n  await client.stream({\n    path: '/',\n    method: 'GET',\n    opaque: { bufs }\n  }, ({ statusCode, headers, opaque: { bufs } }) => {\n    console.log(`response received ${statusCode}`)\n    console.log('headers', headers)\n    return new Writable({\n      write (chunk, encoding, callback) {\n        bufs.push(chunk)\n        callback()\n      }\n    })\n  })\n\n  console.log(Buffer.concat(bufs).toString('utf-8'))\n\n  client.close()\n  server.close()\n} catch (error) {\n  console.error(error)\n}\n</code></pre>"
            },
            {
              "textRaw": "`dispatcher.upgrade(options[, callback])`",
              "name": "upgrade",
              "type": "method",
              "meta": {
                "added": [
                  "v4.0.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`options` {Object}",
                      "name": "options",
                      "type": "Object",
                      "options": [
                        {
                          "textRaw": "`path` {string} The request path.",
                          "name": "path",
                          "type": "string",
                          "desc": "The request path."
                        },
                        {
                          "textRaw": "`method` {string} The HTTP method. **Default:** `'GET'`.",
                          "name": "method",
                          "type": "string",
                          "default": "`'GET'`",
                          "desc": "The HTTP method."
                        },
                        {
                          "textRaw": "`headers` {UndiciHeaders} Request headers. **Default:** `null`.",
                          "name": "headers",
                          "type": "UndiciHeaders",
                          "default": "`null`",
                          "desc": "Request headers."
                        },
                        {
                          "textRaw": "`protocol` {string} A comma-separated list of protocols, in descending preference order. **Default:** `'Websocket'`.",
                          "name": "protocol",
                          "type": "string",
                          "default": "`'Websocket'`",
                          "desc": "A comma-separated list of protocols, in descending preference order."
                        },
                        {
                          "textRaw": "`signal` {AbortSignal|EventEmitter|null} A signal used to abort the request. **Default:** `null`.",
                          "name": "signal",
                          "type": "AbortSignal|EventEmitter|null",
                          "default": "`null`",
                          "desc": "A signal used to abort the request."
                        },
                        {
                          "textRaw": "`responseHeaders` {string|null} Set to `'raw'` to return the response headers as a raw array. **Default:** `null`.",
                          "name": "responseHeaders",
                          "type": "string|null",
                          "default": "`null`",
                          "desc": "Set to `'raw'` to return the response headers as a raw array."
                        }
                      ]
                    },
                    {
                      "textRaw": "`callback` {Function} (optional) Invoked when the upgrade completes.",
                      "name": "callback",
                      "type": "Function",
                      "desc": "(optional) Invoked when the upgrade completes.",
                      "options": [
                        {
                          "textRaw": "`error` {Error|null}",
                          "name": "error",
                          "type": "Error|null"
                        },
                        {
                          "textRaw": "`data` {Object}",
                          "name": "data",
                          "type": "Object",
                          "options": [
                            {
                              "textRaw": "`headers` {Object} The response headers.",
                              "name": "headers",
                              "type": "Object",
                              "desc": "The response headers."
                            },
                            {
                              "textRaw": "`socket` {Duplex} The upgraded socket.",
                              "name": "socket",
                              "type": "Duplex",
                              "desc": "The upgraded socket."
                            },
                            {
                              "textRaw": "`opaque` {any}",
                              "name": "opaque",
                              "type": "any"
                            }
                          ]
                        }
                      ],
                      "optional": true
                    }
                  ],
                  "return": {
                    "textRaw": "Returns: {Promise} A `Promise` is returned only when `callback` is omitted. It resolves with the `data` object described above.",
                    "name": "return",
                    "type": "Promise",
                    "desc": "A `Promise` is returned only when `callback` is omitted. It resolves with the `data` object described above."
                  }
                }
              ],
              "desc": "<p>Upgrades to a different protocol. See\n<a href=\"https://developer.mozilla.org/en-US/docs/Web/HTTP/Protocol_upgrade_mechanism\">MDN: Protocol upgrade mechanism</a> for more details.</p>\n<pre><code class=\"language-mjs\">import { createServer } from 'node:http'\nimport { Client } from 'undici'\nimport { once } from 'node:events'\n\nconst server = createServer((request, response) => {\n  response.statusCode = 101\n  response.setHeader('connection', 'upgrade')\n  response.setHeader('upgrade', request.headers.upgrade)\n  response.end()\n}).listen()\n\nawait once(server, 'listening')\n\nconst client = new Client(`http://localhost:${server.address().port}`)\n\ntry {\n  const { headers, socket } = await client.upgrade({ path: '/' })\n  socket.on('end', () => {\n    console.log(`upgrade: ${headers.upgrade}`) // upgrade: Websocket\n    client.close()\n    server.close()\n  })\n  socket.end()\n} catch (error) {\n  console.error(error)\n  client.close()\n  server.close()\n}\n</code></pre>"
            },
            {
              "textRaw": "`dispatcher.compose(interceptors[, interceptor])`",
              "name": "compose",
              "type": "method",
              "meta": {
                "added": [
                  "v6.9.0"
                ],
                "changes": []
              },
              "signatures": [
                {
                  "params": [
                    {
                      "textRaw": "`interceptors` {Array|Function} An array of interceptor functions, or the first of several interceptors passed as separate arguments.",
                      "name": "interceptors",
                      "type": "Array|Function",
                      "desc": "An array of interceptor functions, or the first of several interceptors passed as separate arguments."
                    },
                    {
                      "name": "interceptor",
                      "optional": true
                    }
                  ],
                  "return": {
                    "textRaw": "Returns: {Dispatcher} A new dispatcher that applies the interceptors over the current dispatcher's `dispatch()` method.",
                    "name": "return",
                    "type": "Dispatcher",
                    "desc": "A new dispatcher that applies the interceptors over the current dispatcher's `dispatch()` method."
                  }
                }
              ],
              "desc": "<p>Composes a new dispatcher from the current dispatcher and the given\ninterceptors. Each interceptor is a function that takes a <code>dispatch</code> method and\nreturns a <code>dispatch</code>-like function with the same signature\n(<code>(options, handler)</code>).</p>\n<p>The order of the interceptors matters: the last interceptor in the chain is the\nfirst to be called. Forking the chain of interceptors can lead to unexpected\nresults.</p>\n<pre><code class=\"language-text\">compose([interceptor1, interceptor2, interceptor3])\n\nRequest flow:\nRequest -> interceptor3 -> interceptor2 -> interceptor1 -> dispatcher.dispatch\n           (called first)  (called second) (called last)\n</code></pre>\n<pre><code class=\"language-mjs\">import { Client, RedirectHandler } from 'undici'\n\nconst redirectInterceptor = dispatch => {\n  return (opts, handler) => {\n    const { maxRedirections } = opts\n\n    if (!maxRedirections) {\n      return dispatch(opts, handler)\n    }\n\n    const redirectHandler = new RedirectHandler(dispatch, maxRedirections, opts, handler)\n    opts = { ...opts, maxRedirections: 0 } // Stop the sub-dispatcher from also redirecting.\n    return dispatch(opts, redirectHandler)\n  }\n}\n\nconst client = new Client('http://localhost:3000').compose(redirectInterceptor)\n\nawait client.request({ path: '/', method: 'GET' })\n</code></pre>\n<p>Interceptors can be chained by calling <code>compose()</code> repeatedly:</p>\n<pre><code class=\"language-mjs\">import { Client } from 'undici'\n\nconst client = new Client('http://localhost:3000')\n  .compose(redirectInterceptor)\n  .compose(retryInterceptor)\n\nawait client.request({ path: '/', method: 'GET' })\n</code></pre>\n<p>For the full list of built-in interceptors provided by undici, see <a href=\"Interceptors.html\">Interceptors</a>.</p>"
            }
          ],
          "events": [
            {
              "textRaw": "Event: `'connect'`",
              "name": "connect",
              "type": "event",
              "meta": {
                "added": [
                  "v4.0.0"
                ],
                "changes": []
              },
              "params": [
                {
                  "textRaw": "`origin` {URL}",
                  "name": "origin",
                  "type": "URL"
                },
                {
                  "textRaw": "`targets` {Array<Dispatcher>}",
                  "name": "targets",
                  "type": "Array<Dispatcher>"
                }
              ],
              "desc": "<p>Emitted when the dispatcher has connected to the origin.</p>"
            },
            {
              "textRaw": "Event: `'disconnect'`",
              "name": "disconnect",
              "type": "event",
              "meta": {
                "added": [
                  "v4.0.0"
                ],
                "changes": []
              },
              "params": [
                {
                  "textRaw": "`origin` {URL}",
                  "name": "origin",
                  "type": "URL"
                },
                {
                  "textRaw": "`targets` {Array<Dispatcher>}",
                  "name": "targets",
                  "type": "Array<Dispatcher>"
                },
                {
                  "textRaw": "`error` {Error}",
                  "name": "error",
                  "type": "Error"
                }
              ],
              "desc": "<p>Emitted when the dispatcher has been disconnected from the origin.</p>\n<p>For HTTP/2, this event is also emitted when the dispatcher receives a\n<a href=\"https://webconcepts.info/concepts/http2-frame-type/0x7\">GOAWAY frame</a>, with an error whose message is <code>HTTP/2: \"GOAWAY\" frame received</code>\nand whose code is <code>UND_ERR_INFO</code>. Because of the binary-framing nature of the\nprotocol, a request may hang if a frame is received between the <code>HEADER</code> and\n<code>DATA</code> frames. It is recommended to handle this event and close the dispatcher to\ncreate a new HTTP/2 session.</p>"
            },
            {
              "textRaw": "Event: `'connectionError'`",
              "name": "connectionError",
              "type": "event",
              "meta": {
                "added": [
                  "v4.0.0"
                ],
                "changes": []
              },
              "params": [
                {
                  "textRaw": "`origin` {URL}",
                  "name": "origin",
                  "type": "URL"
                },
                {
                  "textRaw": "`targets` {Array<Dispatcher>}",
                  "name": "targets",
                  "type": "Array<Dispatcher>"
                },
                {
                  "textRaw": "`error` {Error}",
                  "name": "error",
                  "type": "Error"
                }
              ],
              "desc": "<p>Emitted when the dispatcher fails to connect to the origin.</p>"
            },
            {
              "textRaw": "Event: `'drain'`",
              "name": "drain",
              "type": "event",
              "meta": {
                "added": [
                  "v4.0.0"
                ],
                "changes": []
              },
              "params": [
                {
                  "textRaw": "`origin` {URL}",
                  "name": "origin",
                  "type": "URL"
                }
              ],
              "desc": "<p>Emitted when the dispatcher is no longer busy and further <a href=\"#dispatcherdispatchoptions-handler\"><code>dispatch()</code></a> calls\ncan make progress.</p>"
            }
          ]
        }
      ],
      "modules": [
        {
          "textRaw": "Pre-built interceptors",
          "name": "pre-built_interceptors",
          "type": "module",
          "desc": "<p>For the full reference of built-in interceptors (<code>dump</code>, <code>retry</code>, <code>redirect</code>,\n<code>decompress</code>, <code>responseError</code>, <code>dns</code>, <code>cache</code>, <code>deduplicate</code>) and their options,\nsee <a href=\"Interceptors.html\">Interceptors</a>.</p>",
          "displayName": "Pre-built interceptors"
        }
      ]
    }
  ]
}