@openclaw/discord 2026.6.11 → 2026.6.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/dist/action-runtime-api.js +1 -1
  2. package/dist/{api-4GFMoWu0.js → api-CjnGBhM3.js} +4 -1
  3. package/dist/api.js +14 -14
  4. package/dist/{approval-handler.runtime-SsFtZQA6.js → approval-handler.runtime-BWPQrzpP.js} +9 -4
  5. package/dist/{audit-CAnmyf2A.js → audit-BwJ_2OjL.js} +3 -3
  6. package/dist/{channel-YA7AbYP3.js → channel-DU4jnQgl.js} +15 -15
  7. package/dist/{channel-actions-BJ3n5Z1l.js → channel-actions-CwmIqnYN.js} +2 -2
  8. package/dist/{channel-actions.runtime-D2QTRgZ9.js → channel-actions.runtime-DvpTfaJ4.js} +5 -5
  9. package/dist/channel-plugin-api.js +1 -1
  10. package/dist/{channel.setup-B1zDEAR7.js → channel.setup-glZ5Y98a.js} +2 -2
  11. package/dist/{components-Dm4c_ce6.js → components-j6lTZBsT.js} +1 -1
  12. package/dist/{conversation-identity-DZ0BD7xO.js → conversation-identity-36FFBwm5.js} +2 -2
  13. package/dist/{directory-config-BK1OhHa3.js → directory-config-BYMFzL29.js} +1 -1
  14. package/dist/directory-contract-api.js +1 -1
  15. package/dist/{directory-live-DP3CmwGf.js → directory-live-9JtJCiu8.js} +2 -2
  16. package/dist/{handle-action.guild-admin-B2cOoU2D.js → handle-action.guild-admin-xxGYrp-I.js} +2 -2
  17. package/dist/index.js +1 -1
  18. package/dist/{manager.runtime-CPHxr9B3.js → manager.runtime-NxCd-PVt.js} +3 -3
  19. package/dist/{message-handler-CKaTgBIV.js → message-handler-cizxbaDc.js} +7 -6
  20. package/dist/{message-handler.preflight--eAiaewz.js → message-handler.preflight-CbD0u7U7.js} +10 -10
  21. package/dist/{message-handler.process-PhKAmrEd.js → message-handler.process-Do4EM591.js} +10 -10
  22. package/dist/{message-utils-O1vK3kPu.js → message-utils-CJeAoISH.js} +1 -1
  23. package/dist/{outbound-adapter-fO_7hbTh.js → outbound-adapter-Dxs6iKEq.js} +62 -131
  24. package/dist/{pluralkit-B3MzPaPU.js → pluralkit-DI6RYaVj.js} +1 -1
  25. package/dist/presence-cache-z1N8MbJ3.js +45 -0
  26. package/dist/{probe-CxnDikWm.js → probe-esE_Oqdm.js} +1 -1
  27. package/dist/{probe.runtime-DLFkSDVB.js → probe.runtime-C3Atgpvr.js} +1 -1
  28. package/dist/{provider-BJaJ20MY.js → provider-B-s93q9s.js} +76 -26
  29. package/dist/{provider-session.runtime-D6xc-60s.js → provider-session.runtime-BKMOqHpd.js} +3 -3
  30. package/dist/provider.runtime-CaTJrpnl.js +2 -0
  31. package/dist/{resolve-allowlist-common-BDpBb8dF.js → resolve-allowlist-common-3gB2Gpmm.js} +1 -1
  32. package/dist/{resolve-channels-iJIjYfRw.js → resolve-channels-B3gQf8QL.js} +3 -3
  33. package/dist/{resolve-users-_fv1mm1f.js → resolve-users-BO10y5fJ.js} +3 -3
  34. package/dist/{runtime-ywXByivr.js → runtime-CFlR3L9X.js} +8 -8
  35. package/dist/runtime-api.actions.js +2 -2
  36. package/dist/runtime-api.js +20 -20
  37. package/dist/runtime-api.lookup.js +5 -5
  38. package/dist/runtime-api.monitor-CRiBIQEI.js +6 -0
  39. package/dist/runtime-api.monitor.js +6 -5
  40. package/dist/runtime-api.send.js +5 -5
  41. package/dist/runtime-api.threads.js +3 -3
  42. package/dist/{send-Dc5uQX5H.js → send-JHxfT4Pk.js} +6 -4
  43. package/dist/{send.components-D4bl20xr.js → send.components-CN35E2Ck.js} +11 -6
  44. package/dist/{send.outbound-5axvwLkl.js → send.outbound-B-cA1Esv.js} +15 -8
  45. package/dist/{send.receipt-B21MspvT.js → send.receipt-CGecJDin.js} +10 -1
  46. package/dist/{send.shared-9082A2sO.js → send.shared-vcbfThdy.js} +107 -16
  47. package/dist/session-binding-contract-api.js +1 -1
  48. package/dist/setup-plugin-api.js +1 -1
  49. package/dist/{subagent-hooks-NTv6B4up.js → subagent-hooks-20wXhVzZ.js} +2 -2
  50. package/dist/subagent-hooks-api.js +1 -1
  51. package/dist/{system-events-BzaI1WpN.js → system-events-DR27TE7p.js} +1 -1
  52. package/dist/{target-resolver-agnOrtOU.js → target-resolver-CDi1gI90.js} +2 -2
  53. package/dist/targets-C6yd3y8R.js +3 -0
  54. package/dist/{thread-bindings-DNitaHVh.js → thread-bindings-DU4T6nDo.js} +4 -4
  55. package/dist/{thread-bindings.discord-api-CjYNuvZa.js → thread-bindings.discord-api-CYkr-3Gj.js} +4 -4
  56. package/dist/{thread-bindings.manager-PZvJ4TJx.js → thread-bindings.manager-BqWs1UE2.js} +3 -3
  57. package/dist/{transcripts-source-Bi8N6h5X.js → transcripts-source-D-lBI5ZD.js} +1 -1
  58. package/dist/transcripts-source-api.js +1 -1
  59. package/dist/{typing-BdRqXUN3.js → typing-xr05bL-r.js} +1 -1
  60. package/node_modules/undici/README.md +8 -2
  61. package/node_modules/undici/docs/docs/api/Agent.md +248 -44
  62. package/node_modules/undici/docs/docs/api/BalancedPool.md +246 -48
  63. package/node_modules/undici/docs/docs/api/CacheStorage.md +171 -13
  64. package/node_modules/undici/docs/docs/api/CacheStore.md +294 -98
  65. package/node_modules/undici/docs/docs/api/Client.md +369 -179
  66. package/node_modules/undici/docs/docs/api/ClientStats.md +80 -14
  67. package/node_modules/undici/docs/docs/api/Connector.md +118 -36
  68. package/node_modules/undici/docs/docs/api/ContentType.md +65 -25
  69. package/node_modules/undici/docs/docs/api/Cookies.md +122 -71
  70. package/node_modules/undici/docs/docs/api/Debug.md +34 -18
  71. package/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +364 -164
  72. package/node_modules/undici/docs/docs/api/Dispatcher.md +485 -1102
  73. package/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +101 -87
  74. package/node_modules/undici/docs/docs/api/Errors.md +503 -40
  75. package/node_modules/undici/docs/docs/api/EventSource.md +294 -32
  76. package/node_modules/undici/docs/docs/api/Fetch.md +680 -31
  77. package/node_modules/undici/docs/docs/api/GlobalInstallation.md +78 -98
  78. package/node_modules/undici/docs/docs/api/H2CClient.md +298 -176
  79. package/node_modules/undici/docs/docs/api/Interceptors.md +414 -0
  80. package/node_modules/undici/docs/docs/api/MockAgent.md +333 -314
  81. package/node_modules/undici/docs/docs/api/MockCallHistory.md +272 -98
  82. package/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +189 -26
  83. package/node_modules/undici/docs/docs/api/MockClient.md +151 -33
  84. package/node_modules/undici/docs/docs/api/MockErrors.md +56 -5
  85. package/node_modules/undici/docs/docs/api/MockPool.md +321 -258
  86. package/node_modules/undici/docs/docs/api/Pool.md +235 -43
  87. package/node_modules/undici/docs/docs/api/PoolStats.md +119 -13
  88. package/node_modules/undici/docs/docs/api/ProxyAgent.md +179 -160
  89. package/node_modules/undici/docs/docs/api/RedirectHandler.md +238 -63
  90. package/node_modules/undici/docs/docs/api/RetryAgent.md +113 -26
  91. package/node_modules/undici/docs/docs/api/RetryHandler.md +161 -77
  92. package/node_modules/undici/docs/docs/api/RoundRobinPool.md +166 -72
  93. package/node_modules/undici/docs/docs/api/SnapshotAgent.md +264 -542
  94. package/node_modules/undici/docs/docs/api/Socks5ProxyAgent.md +162 -187
  95. package/node_modules/undici/docs/docs/api/Util.md +68 -11
  96. package/node_modules/undici/docs/docs/api/WebSocket.md +475 -80
  97. package/node_modules/undici/docs/docs/api/api-lifecycle.md +100 -32
  98. package/node_modules/undici/docs/docs/best-practices/client-certificate.md +2 -0
  99. package/node_modules/undici/docs/docs/best-practices/crawling.md +3 -1
  100. package/node_modules/undici/docs/docs/best-practices/migrating-from-v7-to-v8.md +6 -4
  101. package/node_modules/undici/docs/docs/best-practices/mocking-request.md +9 -7
  102. package/node_modules/undici/docs/docs/best-practices/proxy.md +3 -1
  103. package/node_modules/undici/docs/docs/best-practices/undici-vs-builtin-fetch.md +10 -8
  104. package/node_modules/undici/docs/docs/best-practices/writing-tests.md +2 -0
  105. package/node_modules/undici/docs/docs/{GettingStarted.md → getting-started.md} +22 -19
  106. package/node_modules/undici/docs/docs/index.md +784 -0
  107. package/node_modules/undici/docs/docs/site.json +125 -0
  108. package/node_modules/undici/docs/docs/type-map.json +79 -0
  109. package/node_modules/undici/lib/api/api-request.js +7 -1
  110. package/node_modules/undici/lib/api/readable.js +47 -2
  111. package/node_modules/undici/lib/cache/memory-cache-store.js +54 -9
  112. package/node_modules/undici/lib/cache/sqlite-cache-store.js +7 -1
  113. package/node_modules/undici/lib/core/errors.js +20 -0
  114. package/node_modules/undici/lib/core/request.js +14 -3
  115. package/node_modules/undici/lib/core/util.js +30 -2
  116. package/node_modules/undici/lib/dispatcher/agent.js +3 -3
  117. package/node_modules/undici/lib/dispatcher/client-h1.js +65 -8
  118. package/node_modules/undici/lib/dispatcher/client-h2.js +265 -142
  119. package/node_modules/undici/lib/dispatcher/proxy-agent.js +40 -6
  120. package/node_modules/undici/lib/global.js +36 -16
  121. package/node_modules/undici/lib/handler/cache-handler.js +269 -61
  122. package/node_modules/undici/lib/handler/cache-revalidation-handler.js +13 -3
  123. package/node_modules/undici/lib/handler/redirect-handler.js +6 -2
  124. package/node_modules/undici/lib/handler/retry-handler.js +87 -23
  125. package/node_modules/undici/lib/interceptor/cache.js +159 -52
  126. package/node_modules/undici/lib/interceptor/decompress.js +9 -2
  127. package/node_modules/undici/lib/mock/mock-interceptor.js +25 -7
  128. package/node_modules/undici/lib/mock/mock-utils.js +39 -10
  129. package/node_modules/undici/lib/util/cache.js +372 -68
  130. package/node_modules/undici/lib/util/date.js +23 -6
  131. package/node_modules/undici/lib/web/cookies/parse.js +3 -2
  132. package/node_modules/undici/lib/web/cookies/util.js +79 -9
  133. package/node_modules/undici/lib/web/eventsource/util.js +1 -1
  134. package/node_modules/undici/lib/web/fetch/body.js +2 -1
  135. package/node_modules/undici/lib/web/fetch/constants.js +1 -1
  136. package/node_modules/undici/lib/web/fetch/index.js +11 -2
  137. package/node_modules/undici/lib/web/fetch/response.js +1 -3
  138. package/node_modules/undici/lib/web/fetch/util.js +4 -1
  139. package/node_modules/undici/package.json +2 -2
  140. package/node_modules/undici/types/client.d.ts +3 -3
  141. package/node_modules/undici/types/cookies.d.ts +1 -1
  142. package/node_modules/undici/types/dispatcher.d.ts +3 -3
  143. package/node_modules/undici/types/errors.d.ts +10 -0
  144. package/node_modules/undici/types/handlers.d.ts +2 -0
  145. package/node_modules/undici/types/mock-interceptor.d.ts +5 -1
  146. package/node_modules/undici/types/proxy-agent.d.ts +7 -0
  147. package/npm-shrinkwrap.json +7 -7
  148. package/package.json +5 -5
  149. package/dist/gateway-registry-DPxmW0Db.js +0 -74
  150. package/dist/provider.runtime-jNlHxUSW.js +0 -2
  151. package/dist/runtime-api.monitor-Bb5AaRzg.js +0 -6
  152. package/dist/targets-ClUPljCU.js +0 -3
@@ -1,103 +1,172 @@
1
- # Class: Client
2
-
3
- Extends: `undici.Dispatcher`
4
-
5
- A basic HTTP/1.1 client, mapped on top a single TCP/TLS connection. Pipelining is disabled by default.
6
-
7
- Requests are not guaranteed to be dispatched in order of invocation.
8
-
9
- ## `new Client(url[, options])`
10
-
11
- Arguments:
12
-
13
- * **url** `URL | string` - Should only include the **protocol, hostname, and port**.
14
- * **options** `ClientOptions` (optional)
15
-
16
- Returns: `Client`
17
-
18
- ### Parameter: `ClientOptions`
19
-
20
- * **bodyTimeout** `number | null` (optional) - Default: `300e3` - The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Defaults to 300 seconds. Please note the `timeout` will be reset if you keep writing data to the socket everytime.
21
- * **headersTimeout** `number | null` (optional) - Default: `300e3` - The amount of time, in milliseconds, the parser will wait to receive the complete HTTP headers while not sending the request. Defaults to 300 seconds.
22
- * **keepAliveMaxTimeout** `number | null` (optional) - Default: `600e3` - The maximum allowed `keepAliveTimeout`, in milliseconds, when overridden by *keep-alive* hints from the server. Defaults to 10 minutes.
23
- * **keepAliveTimeout** `number | null` (optional) - Default: `4e3` - The timeout, in milliseconds, after which a socket without active requests will time out. Monitors time between activity on a connected socket. This value may be overridden by *keep-alive* hints from the server. See [MDN: HTTP - Headers - Keep-Alive directives](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive#directives) for more details. Defaults to 4 seconds.
24
- * **keepAliveTimeoutThreshold** `number | null` (optional) - Default: `2e3` - A number of milliseconds subtracted from server *keep-alive* hints when overriding `keepAliveTimeout` to account for timing inaccuracies caused by e.g. transport latency. Defaults to 2 seconds.
25
- * **maxHeaderSize** `number | null` (optional) - Default: `--max-http-header-size` or `16384` - The maximum length of request headers in bytes. Defaults to Node.js' --max-http-header-size or 16KiB.
26
- * **maxResponseSize** `number | null` (optional) - Default: `-1` - The maximum length of response body in bytes. Set to `-1` to disable.
27
- * **webSocket** `WebSocketOptions` (optional) - WebSocket-specific configuration options.
28
- * **maxFragments** `number` (optional) - Default: `131072` - Maximum number of fragments in a message. Set to 0 to disable the limit.
29
- * **maxPayloadSize** `number` (optional) - Default: `134217728` (128 MB) - Maximum allowed payload size in bytes for WebSocket messages. Applied to uncompressed messages, compressed frame payloads, and decompressed (permessage-deflate) messages. Set to 0 to disable the limit.
30
- * **pipelining** `number | null` (optional) - Default: `1` - The amount of concurrent requests to be sent over the single TCP/TLS connection according to [RFC7230](https://tools.ietf.org/html/rfc7230#section-6.3.2). Carefully consider your workload and environment before enabling concurrent requests as pipelining may reduce performance if used incorrectly. Pipelining is sensitive to network stack settings as well as head of line blocking caused by e.g. long running requests. Set to `0` to disable keep-alive connections. This option has no effect once HTTP/2 is negotiated — see `maxConcurrentStreams` for the h2 dispatch ceiling.
31
- * **connect** `ConnectOptions | Function | null` (optional) - Default: `null` - Configures how undici establishes TCP/TLS connections. Accepts two forms:
32
- * **Object (`ConnectOptions`)**: Options passed directly to the internal [`buildConnector()`](/docs/docs/api/Connector.md). This is the simplest way to customize TLS or socket behavior (e.g., setting `rejectUnauthorized`, `ca`, `socketPath`). See [`ConnectOptions`](#parameter-connectoptions) for available fields.
33
- * **Function**: A custom connector with the signature `(options, callback)`, where `options` contains `{ hostname, host, protocol, port, servername, localAddress, httpSocket }` and `callback` follows `(error, socket)`. Useful when you need full control over socket creation, such as adding custom validation or proxy logic. When a function is provided, undici wraps it to automatically inject `socketPath` and `allowH2` into the `options` argument if those values are set on the client.
34
- * **strictContentLength** `Boolean` (optional) - Default: `true` - Whether to treat request content length mismatches as errors. If true, an error is thrown when the request content-length header doesn't match the length of the request body. **Security Warning:** Disabling this option can expose your application to HTTP Request Smuggling attacks, where mismatched content-length headers cause servers and proxies to interpret request boundaries differently. This can lead to cache poisoning, credential hijacking, and bypassing security controls. Only disable this in controlled environments where you fully trust the request source.
35
- * **autoSelectFamily**: `boolean` (optional) - Default: depends on local Node version, on Node 18.13.0 and above is `false`. Enables a family autodetection algorithm that loosely implements section 5 of [RFC 8305](https://tools.ietf.org/html/rfc8305#section-5). See [here](https://nodejs.org/api/net.html#socketconnectoptions-connectlistener) for more details. This option is ignored if not supported by the current Node version.
36
- * **autoSelectFamilyAttemptTimeout**: `number` - Default: depends on local Node version, on Node 18.13.0 and above is `250`. The amount of time in milliseconds to wait for a connection attempt to finish before trying the next address when using the `autoSelectFamily` option. See [here](https://nodejs.org/api/net.html#socketconnectoptions-connectlistener) for more details.
37
- * **allowH2**: `boolean` - Default: `true`. Enables support for H2 if the server has assigned bigger priority to it through ALPN negotiation.
38
- * **useH2c**: `boolean` - Default: `false`. Enforces h2c for non-https connections.
39
- * **maxConcurrentStreams**: `number` - Default: `100`. The maximum number of concurrent HTTP/2 streams per session. When `allowH2` negotiates h2, this — not `pipelining` (which is HTTP/1.1 only, per [RFC7230](https://tools.ietf.org/html/rfc7230#section-6.3.2)) — is the ceiling the Client uses to dispatch in-flight requests on a shared session. The same value is advertised to the server as `peerMaxConcurrentStreams`, capping how many streams the server may push back. The initial value is replaced by the server's `SETTINGS_MAX_CONCURRENT_STREAMS` whenever the server sends one, so a user-supplied value acts as a pre-`SETTINGS` default rather than a hard cap.
40
- * **initialWindowSize**: `number` (optional) - Default: `262144` (256KB). Sets the HTTP/2 stream-level flow-control window size (SETTINGS_INITIAL_WINDOW_SIZE). Must be a positive integer greater than 0. This default is higher than Node.js core's default (65535 bytes) to improve throughput, Node's choice is very conservative for current high-bandwith networks. See [RFC 7540 Section 6.9.2](https://datatracker.ietf.org/doc/html/rfc7540#section-6.9.2) for more details.
41
- * **connectionWindowSize**: `number` (optional) - Default `524288` (512KB). Sets the HTTP/2 connection-level flow-control window size using `ClientHttp2Session.setLocalWindowSize()`. Must be a positive integer greater than 0. This provides better flow control for the entire connection across multiple streams. See [Node.js HTTP/2 documentation](https://nodejs.org/api/http2.html#clienthttp2sessionsetlocalwindowsize) for more details.
42
- * **pingInterval**: `number` - Default: `60e3`. The time interval in milliseconds between PING frames sent to the server. Set to `0` to disable PING frames. This is only applicable for HTTP/2 connections. This will emit a `ping` event on the client with the duration of the ping in milliseconds.
43
-
44
- > **Notes about HTTP/2**
45
- > - It only works under TLS connections. h2c is not supported.
46
- > - The server must support HTTP/2 and choose it as the protocol during the ALPN negotiation.
47
- > - The server must not have a bigger priority for HTTP/1.1 than HTTP/2.
48
- > - Pseudo headers are automatically attached to the request. If you try to set them, they will be overwritten.
49
- > - The `:path` header is automatically set to the request path.
50
- > - The `:method` header is automatically set to the request method.
51
- > - The `:scheme` header is automatically set to the request scheme.
52
- > - The `:authority` header is automatically set to the request `host[:port]`.
53
- > - `PUSH` frames are yet not supported.
54
-
55
- #### Parameter: `ConnectOptions`
56
-
57
- Every Tls option, see [here](https://nodejs.org/api/tls.html#tls_tls_connect_options_callback).
58
- Furthermore, the following options can be passed:
59
-
60
- * **socketPath** `string | null` (optional) - Default: `null` - An IPC endpoint, either Unix domain socket or Windows named pipe.
61
- * **maxCachedSessions** `number | null` (optional) - Default: `100` - Maximum number of TLS cached sessions. Use 0 to disable TLS session caching. Default: 100.
62
- * **timeout** `number | null` (optional) - In milliseconds, Default `10e3`.
63
- * **servername** `string | null` (optional)
64
- * **keepAlive** `boolean | null` (optional) - Default: `true` - TCP keep-alive enabled
65
- * **keepAliveInitialDelay** `number | null` (optional) - Default: `60000` - TCP keep-alive interval for the socket in milliseconds
66
-
67
- ### Example - Basic Client instantiation
68
-
69
- This will instantiate the undici Client, but it will not connect to the origin until something is queued. Consider using `client.connect` to prematurely connect to the origin, or just call `client.request`.
70
-
71
- ```js
72
- 'use strict'
1
+ # Client
2
+
3
+ <!--introduced_in=v1.0.0-->
4
+
5
+ <!--type=module-->
6
+
7
+ <!-- source_link=lib/dispatcher/client.js -->
8
+
9
+ > Stability: 2 - Stable
10
+
11
+ A basic HTTP/1.1 client mapped on top of a single TCP/TLS connection. When the
12
+ server supports HTTP/2 and selects it during ALPN negotiation, the same
13
+ connection is used for HTTP/2. Pipelining is disabled by default.
14
+
15
+ `Client` extends [`Dispatcher`][] and is the lowest-level dispatcher in undici:
16
+ it manages exactly one origin over one connection. For pooling across multiple
17
+ connections use [`Pool`][], and for routing across multiple origins use
18
+ [`Agent`][]. Requests are not guaranteed to be dispatched in the order in which
19
+ they are invoked.
20
+
21
+ ```mjs
73
22
  import { Client } from 'undici'
74
23
 
75
24
  const client = new Client('http://localhost:3000')
25
+ const { statusCode, body } = await client.request({ path: '/', method: 'GET' })
76
26
  ```
77
27
 
78
- ### Example - Connect with TLS options (object form)
28
+ ## Class: `Client`
29
+
30
+ <!-- YAML
31
+ added: v1.0.0
32
+ -->
33
+
34
+ * Extends: {Dispatcher}
35
+
36
+ ### `new Client(url[, options])`
37
+
38
+ <!-- YAML
39
+ added: v1.0.0
40
+ -->
41
+
42
+ * `url` {URL|string} The origin to connect to. Only the protocol, hostname, and
43
+ port are used.
44
+ * `options` {Object} (optional)
45
+ * `bodyTimeout` {number|null} The timeout, in milliseconds, after which a
46
+ request times out while receiving body data. Monitors the time between
47
+ consecutive body chunks. Use `0` to disable it entirely. **Default:**
48
+ `300e3`.
49
+ * `headersTimeout` {number|null} The timeout, in milliseconds, the parser
50
+ waits to receive the complete HTTP headers before the request times out. Use
51
+ `0` to disable it entirely. **Default:** `300e3`.
52
+ HTTP/1.1 headers/body parser timeouts are not guaranteed to fire with exact
53
+ millisecond precision: delays up to 1000ms use native timers, while larger
54
+ delays use undici's lower-overhead fast timers with a target resolution
55
+ around 500ms.
56
+ * `connectTimeout` {number|null} The timeout, in milliseconds, for
57
+ establishing a socket connection. Use `0` to disable it entirely.
58
+ **Default:** `10e3`.
59
+ * `keepAliveTimeout` {number|null} The timeout, in milliseconds, after which a
60
+ socket with no active requests times out. Monitors the time between activity
61
+ on a connected socket. This value may be overridden by *keep-alive* hints
62
+ from the server. **Default:** `4e3`.
63
+ * `keepAliveMaxTimeout` {number|null} The maximum allowed `keepAliveTimeout`,
64
+ in milliseconds, when overridden by *keep-alive* hints from the server.
65
+ **Default:** `600e3`.
66
+ * `keepAliveTimeoutThreshold` {number|null} A number of milliseconds
67
+ subtracted from server *keep-alive* hints when overriding `keepAliveTimeout`,
68
+ to account for timing inaccuracies caused by e.g. transport latency.
69
+ **Default:** `2e3`.
70
+ * `maxHeaderSize` {number|null} The maximum length of request headers, in
71
+ bytes. **Default:** the value of Node.js' `--max-http-header-size` or
72
+ `16384` (16 KiB).
73
+ * `maxResponseSize` {number|null} The maximum length of a response body, in
74
+ bytes. Set to `-1` to disable it. **Default:** `-1`.
75
+ * `maxRequestsPerClient` {number|null} The maximum number of requests to send
76
+ over a single connection before the socket is reset. Use `0` to disable this
77
+ limit. **Default:** `null`.
78
+ * `localAddress` {string|null} The local IP address the socket should connect
79
+ from. **Default:** `null`.
80
+ * `pipelining` {number|null} The number of concurrent requests sent over the
81
+ single connection, per [RFC 7230, section 6.3.2][]. Only enable values
82
+ greater than `1` when the remote server is trusted. Set to `0` to disable
83
+ keep-alive connections. Has no effect once HTTP/2 is negotiated; see
84
+ `maxConcurrentStreams` for the HTTP/2 dispatch ceiling. **Default:** `1`.
85
+ * `connect` {Object|Function|null} Configures how connections are established.
86
+ Either a `ConnectOptions` object passed to the built-in
87
+ [`buildConnector`][] (every [`tls.connect()`][] option is accepted, plus the
88
+ fields below), or a custom connector function with the signature
89
+ `(options, callback)`. **Default:** `null`.
90
+ * `socketPath` {string|null} An IPC endpoint, either a Unix domain socket or
91
+ a Windows named pipe. **Default:** `null`.
92
+ * `maxCachedSessions` {number|null} The maximum number of cached TLS
93
+ sessions. Use `0` to disable TLS session caching. **Default:** `100`.
94
+ * `timeout` {number|null} The connection timeout, in milliseconds.
95
+ **Default:** `10e3`.
96
+ * `servername` {string|null} The TLS server name used for SNI.
97
+ * `keepAlive` {boolean|null} Whether TCP keep-alive is enabled on the socket.
98
+ **Default:** `true`.
99
+ * `keepAliveInitialDelay` {number|null} The TCP keep-alive interval for the
100
+ socket, in milliseconds. **Default:** `60000`.
101
+ * `strictContentLength` {boolean} Whether to throw when the request
102
+ `content-length` header does not match the length of the request body.
103
+ Disabling this exposes the application to HTTP request smuggling; only do so
104
+ in controlled environments where the request source is fully trusted.
105
+ **Default:** `true`.
106
+ * `autoSelectFamily` {boolean} Enables a family autodetection algorithm that
107
+ loosely implements section 5 of [RFC 8305][]. Ignored if unsupported by the
108
+ current Node.js version. **Default:** `false`.
109
+ * `autoSelectFamilyAttemptTimeout` {number} The time, in milliseconds, to wait
110
+ for a connection attempt to finish before trying the next address when
111
+ `autoSelectFamily` is enabled. **Default:** `250`.
112
+ * `allowH2` {boolean} Enables HTTP/2 support when the server assigns it a
113
+ higher priority through ALPN negotiation. **Default:** `true`.
114
+ * `useH2c` {boolean} Enforces h2c (HTTP/2 cleartext) for non-HTTPS
115
+ connections. **Default:** `false`.
116
+ * `maxConcurrentStreams` {number} The maximum number of concurrent HTTP/2
117
+ streams for a single session. Once h2 is negotiated this — not `pipelining`,
118
+ which is HTTP/1.1 only — is the ceiling used to dispatch in-flight requests.
119
+ It may be overridden by the server's `SETTINGS_MAX_CONCURRENT_STREAMS`
120
+ frame. **Default:** `100`.
121
+ * `initialWindowSize` {number} The HTTP/2 stream-level flow-control window
122
+ size (`SETTINGS_INITIAL_WINDOW_SIZE`). Must be a positive integer.
123
+ **Default:** `262144`.
124
+ * `connectionWindowSize` {number} The HTTP/2 connection-level flow-control
125
+ window size set via `ClientHttp2Session.setLocalWindowSize()`. Must be a
126
+ positive integer. **Default:** `524288`.
127
+ * `pingInterval` {number} The time interval, in milliseconds, between HTTP/2
128
+ PING frames. Set to `0` to disable PING frames. Applies only to HTTP/2
129
+ connections and emits a `ping` event on the client. **Default:** `60e3`.
130
+ * `webSocket` {Object} (optional) WebSocket-specific configuration.
131
+ * `maxFragments` {number} The maximum number of fragments in a message. Set
132
+ to `0` to disable the limit. **Default:** `131072`.
133
+ * `maxPayloadSize` {number} The maximum allowed payload size, in bytes, for
134
+ WebSocket messages. Applied to uncompressed messages, compressed frame
135
+ payloads, and decompressed (`permessage-deflate`) messages. Set to `0` to
136
+ disable the limit. **Default:** `134217728`.
137
+ * Returns: {Client}
138
+
139
+ Instantiating a `Client` does not open a connection; the connection is
140
+ established lazily once a request is queued. Call `client.connect()` to connect
141
+ eagerly.
142
+
143
+ > Notes about HTTP/2:
144
+ >
145
+ > * Pseudo headers (`:path`, `:method`, `:scheme`, `:authority`) are attached
146
+ > automatically and overwrite any user-provided values.
147
+ > * The server must support HTTP/2 and select it during ALPN negotiation, and
148
+ > must not give HTTP/1.1 a higher priority than HTTP/2.
149
+ > * `PUSH` frames are not supported.
150
+
151
+ ```mjs displayName="Basic instantiation"
152
+ import { Client } from 'undici'
79
153
 
80
- Pass a `ConnectOptions` object to customize the TLS connection. The options are forwarded to the internal `buildConnector()`.
154
+ const client = new Client('http://localhost:3000')
155
+ ```
81
156
 
82
- ```js
83
- 'use strict'
157
+ ```mjs displayName="TLS options (object connector)"
84
158
  import { Client } from 'undici'
85
- import fs from 'node:fs'
159
+ import { readFileSync } from 'node:fs'
86
160
 
87
161
  const client = new Client('https://localhost:3000', {
88
162
  connect: {
89
163
  rejectUnauthorized: false,
90
- ca: fs.readFileSync('./ca-cert.pem')
164
+ ca: readFileSync('./ca-cert.pem')
91
165
  }
92
166
  })
93
167
  ```
94
168
 
95
- ### Example - Connect via Unix domain socket
96
-
97
- Use the `socketPath` option to connect through an IPC endpoint instead of a TCP connection.
98
-
99
- ```js
100
- 'use strict'
169
+ ```mjs displayName="Unix domain socket"
101
170
  import { Client } from 'undici'
102
171
 
103
172
  const client = new Client('http://localhost:3000', {
@@ -107,14 +176,20 @@ const client = new Client('http://localhost:3000', {
107
176
  })
108
177
  ```
109
178
 
110
- ### Example - Custom connector (function form)
111
-
112
- Pass a function for full control over socket creation. This allows you to perform additional checks on the socket, use a proxy, or implement custom connection logic.
179
+ ```mjs displayName="Custom DNS lookup"
180
+ import { Client } from 'undici'
181
+ import dns from 'node:dns'
113
182
 
114
- > **Note:** When a function is provided, undici wraps it to automatically inject `socketPath` and `allowH2` into the first argument (`options`) when those values are set on the client.
183
+ const client = new Client('https://example.com', {
184
+ connect: {
185
+ lookup (hostname, options, callback) {
186
+ dns.lookup(hostname, { ...options, family: 4 }, callback)
187
+ }
188
+ }
189
+ })
190
+ ```
115
191
 
116
- ```js
117
- 'use strict'
192
+ ```mjs displayName="Custom connector (function)"
118
193
  import { Client, buildConnector } from 'undici'
119
194
 
120
195
  const connector = buildConnector({ rejectUnauthorized: false })
@@ -123,9 +198,6 @@ const client = new Client('https://localhost:3000', {
123
198
  connector(opts, (err, socket) => {
124
199
  if (err) {
125
200
  cb(err)
126
- } else if (/* assertion */) {
127
- socket.destroy()
128
- cb(new Error('kaboom'))
129
201
  } else {
130
202
  cb(null, socket)
131
203
  }
@@ -134,83 +206,180 @@ const client = new Client('https://localhost:3000', {
134
206
  })
135
207
  ```
136
208
 
137
- For more details on building custom connectors, see [Connector](/docs/docs/api/Connector.md).
209
+ When a connector function is provided, undici wraps it to automatically inject
210
+ `socketPath` and `allowH2` into the `options` argument when those values are set
211
+ on the client. See [`Connector`][] for details on building custom connectors.
212
+
213
+ ### `client.close([callback])`
214
+
215
+ <!-- YAML
216
+ added: v1.0.0
217
+ -->
218
+
219
+ Implements [`dispatcher.close([callback])`][]. Closes the client gracefully,
220
+ waiting for enqueued requests to complete before resolving.
221
+
222
+ ### `client.destroy([error[, callback]])`
223
+
224
+ <!-- YAML
225
+ added: v1.0.0
226
+ -->
227
+
228
+ Implements [`dispatcher.destroy([error[, callback]])`][]. Destroys the client
229
+ abruptly, aborting all pending and running requests, and waits until the socket
230
+ is closed before invoking `callback` (or resolving the returned promise).
231
+
232
+ ### `client.connect(options[, callback])`
233
+
234
+ <!-- YAML
235
+ added: v1.0.0
236
+ -->
237
+
238
+ * `options` {Object} The connect options, identical to
239
+ [`dispatcher.connect()`][] except that `origin` is omitted because the client
240
+ is bound to a single origin.
241
+ * `callback` {Function} (optional)
242
+ * Returns: {Promise|void} A promise when `callback` is not provided.
243
+
244
+ Starts a connection to the client's origin and tunnels a connection through it,
245
+ as defined by [`dispatcher.connect()`][].
138
246
 
139
- ## Instance Methods
247
+ ### `client.dispatch(options, handlers)`
140
248
 
141
- ### `Client.close([callback])`
249
+ <!-- YAML
250
+ added: v1.0.0
251
+ -->
142
252
 
143
- Implements [`Dispatcher.close([callback])`](/docs/docs/api/Dispatcher.md#dispatcherclosecallback-promise).
253
+ Implements [`dispatcher.dispatch(options, handler)`][]. This is the lowest-level
254
+ API used by all other request methods; prefer `client.request()` for most use
255
+ cases.
144
256
 
145
- ### `Client.destroy([error, callback])`
257
+ ### `client.pipeline(options, handler)`
146
258
 
147
- Implements [`Dispatcher.destroy([error, callback])`](/docs/docs/api/Dispatcher.md#dispatcherdestroyerror-callback-promise).
259
+ <!-- YAML
260
+ added: v1.0.0
261
+ -->
148
262
 
149
- Waits until socket is closed before invoking the callback (or returning a promise if no callback is provided).
263
+ See [`dispatcher.pipeline(options, handler)`][]. Sends a request and returns a
264
+ {Duplex} stream that the request body is written to and the response body is
265
+ read from.
150
266
 
151
- ### `Client.connect(options[, callback])`
267
+ ### `client.request(options[, callback])`
152
268
 
153
- See [`Dispatcher.connect(options[, callback])`](/docs/docs/api/Dispatcher.md#dispatcherconnectoptions-callback).
269
+ <!-- YAML
270
+ added: v1.0.0
271
+ -->
154
272
 
155
- ### `Client.dispatch(options, handlers)`
273
+ * `options` {Object}
274
+ * `callback` {Function} (optional)
275
+ * Returns: {Promise|void} A promise resolving to the response data when
276
+ `callback` is not provided.
156
277
 
157
- Implements [`Dispatcher.dispatch(options, handlers)`](/docs/docs/api/Dispatcher.md#dispatcherdispatchoptions-handler).
278
+ See [`dispatcher.request(options[, callback])`][]. Performs an HTTP request and
279
+ returns its status code, headers, trailers, and a readable body stream.
158
280
 
159
- ### `Client.pipeline(options, handler)`
281
+ ```mjs
282
+ import { Client } from 'undici'
283
+
284
+ const client = new Client('http://localhost:3000')
285
+ const { statusCode, headers, body } = await client.request({
286
+ path: '/',
287
+ method: 'GET'
288
+ })
289
+
290
+ console.log(statusCode)
291
+ for await (const chunk of body) {
292
+ console.log(chunk.toString())
293
+ }
294
+ ```
160
295
 
161
- See [`Dispatcher.pipeline(options, handler)`](/docs/docs/api/Dispatcher.md#dispatcherpipelineoptions-handler).
296
+ ### `client.stream(options, factory[, callback])`
162
297
 
163
- ### `Client.request(options[, callback])`
298
+ <!-- YAML
299
+ added: v1.0.0
300
+ -->
164
301
 
165
- See [`Dispatcher.request(options [, callback])`](/docs/docs/api/Dispatcher.md#dispatcherrequestoptions-callback).
302
+ * `options` {Object}
303
+ * `factory` {Function} Returns a {Writable} the response body is piped into.
304
+ * `callback` {Function} (optional)
305
+ * Returns: {Promise|void} A promise when `callback` is not provided.
166
306
 
167
- ### `Client.stream(options, factory[, callback])`
307
+ See [`dispatcher.stream(options, factory[, callback])`][]. A faster alternative
308
+ to `client.request()` when the destination of the response body is known in
309
+ advance.
168
310
 
169
- See [`Dispatcher.stream(options, factory[, callback])`](/docs/docs/api/Dispatcher.md#dispatcherstreamoptions-factory-callback).
311
+ ### `client.upgrade(options[, callback])`
170
312
 
171
- ### `Client.upgrade(options[, callback])`
313
+ <!-- YAML
314
+ added: v1.0.0
315
+ -->
172
316
 
173
- See [`Dispatcher.upgrade(options[, callback])`](/docs/docs/api/Dispatcher.md#dispatcherupgradeoptions-callback).
317
+ * `options` {Object}
318
+ * `callback` {Function} (optional)
319
+ * Returns: {Promise|void} A promise when `callback` is not provided.
174
320
 
175
- ## Instance Properties
321
+ See [`dispatcher.upgrade(options[, callback])`][]. Upgrades a connection to a
322
+ different protocol, such as for WebSocket or HTTP `CONNECT`.
176
323
 
177
- ### `Client.closed`
324
+ ### `client.closed`
178
325
 
179
- * `boolean`
326
+ <!-- YAML
327
+ added: v1.0.0
328
+ -->
329
+
330
+ * Type: {boolean}
180
331
 
181
332
  `true` after `client.close()` has been called.
182
333
 
183
- ### `Client.destroyed`
334
+ ### `client.destroyed`
184
335
 
185
- * `boolean`
336
+ <!-- YAML
337
+ added: v1.0.0
338
+ -->
186
339
 
187
- `true` after `client.destroyed()` has been called or `client.close()` has been called and the client shutdown has completed.
340
+ * Type: {boolean}
188
341
 
189
- ### `Client.pipelining`
342
+ `true` after `client.destroy()` has been called, or after `client.close()` has
343
+ been called and the client shutdown has completed.
190
344
 
191
- * `number`
345
+ ### `client.pipelining`
192
346
 
193
- Property to get and set the pipelining factor.
347
+ <!-- YAML
348
+ added: v1.0.0
349
+ -->
194
350
 
195
- ## Instance Events
351
+ * Type: {number}
196
352
 
197
- ### Event: `'connect'`
353
+ The pipelining factor. This property can be read and written to adjust the
354
+ number of concurrent requests sent over the connection. Only enable pipelining
355
+ with trusted remote servers.
198
356
 
199
- See [Dispatcher Event: `'connect'`](/docs/docs/api/Dispatcher.md#event-connect).
357
+ ### `client.stats`
200
358
 
201
- Parameters:
359
+ <!-- YAML
360
+ added: v7.9.0
361
+ -->
202
362
 
203
- * **origin** `URL`
204
- * **targets** `Array<Dispatcher>`
363
+ * Type: {ClientStats}
205
364
 
206
- Emitted when a socket has been created and connected. The client will connect once `client.size > 0`.
365
+ Aggregate statistics for the client. See [`ClientStats`][].
366
+
367
+ ### Event: `'connect'`
207
368
 
208
- #### Example - Client connect event
369
+ <!-- YAML
370
+ added: v1.0.0
371
+ -->
209
372
 
210
- ```js
211
- import { createServer } from 'http'
373
+ * `origin` {URL}
374
+ * `targets` {Array<Dispatcher>}
375
+
376
+ Emitted when a socket has been created and connected. The client connects once
377
+ `client.size > 0`. See [`Dispatcher` Event: `'connect'`][].
378
+
379
+ ```mjs
380
+ import { createServer } from 'node:http'
212
381
  import { Client } from 'undici'
213
- import { once } from 'events'
382
+ import { once } from 'node:events'
214
383
 
215
384
  const server = createServer((request, response) => {
216
385
  response.end('Hello, World!')
@@ -221,43 +390,40 @@ await once(server, 'listening')
221
390
  const client = new Client(`http://localhost:${server.address().port}`)
222
391
 
223
392
  client.on('connect', (origin) => {
224
- console.log(`Connected to ${origin}`) // should print before the request body statement
393
+ console.log(`Connected to ${origin}`)
225
394
  })
226
395
 
227
- try {
228
- const { body } = await client.request({
229
- path: '/',
230
- method: 'GET'
231
- })
232
- body.setEncoding('utf-8')
233
- body.on('data', console.log)
234
- client.close()
235
- server.close()
236
- } catch (error) {
237
- console.error(error)
238
- client.close()
239
- server.close()
240
- }
396
+ const { body } = await client.request({ path: '/', method: 'GET' })
397
+ body.setEncoding('utf8')
398
+ body.on('data', console.log)
399
+
400
+ client.close()
401
+ server.close()
241
402
  ```
242
403
 
243
404
  ### Event: `'disconnect'`
244
405
 
245
- See [Dispatcher Event: `'disconnect'`](/docs/docs/api/Dispatcher.md#event-disconnect).
246
-
247
- Parameters:
248
-
249
- * **origin** `URL`
250
- * **targets** `Array<Dispatcher>`
251
- * **error** `Error`
252
-
253
- Emitted when socket has disconnected. The error argument of the event is the error which caused the socket to disconnect. The client will reconnect if or once `client.size > 0`.
254
-
255
- #### Example - Client disconnect event
256
-
257
- ```js
258
- import { createServer } from 'http'
406
+ <!-- YAML
407
+ added: v1.0.0
408
+ changes:
409
+ - version: v4.0.0
410
+ pr-url: https://github.com/nodejs/undici/pull/771
411
+ description: The event is only emitted if the client had previously
412
+ connected.
413
+ -->
414
+
415
+ * `origin` {URL}
416
+ * `targets` {Array<Dispatcher>}
417
+ * `error` {Error}
418
+
419
+ Emitted when a socket has disconnected. The `error` argument is the error that
420
+ caused the disconnection. The client reconnects if or once `client.size > 0`.
421
+ See [`Dispatcher` Event: `'disconnect'`][].
422
+
423
+ ```mjs
424
+ import { createServer } from 'node:http'
259
425
  import { Client } from 'undici'
260
- import { once } from 'events'
426
+ import { once } from 'node:events'
261
427
 
262
428
  const server = createServer((request, response) => {
263
429
  response.destroy()
@@ -272,12 +438,10 @@ client.on('disconnect', (origin) => {
272
438
  })
273
439
 
274
440
  try {
275
- await client.request({
276
- path: '/',
277
- method: 'GET'
278
- })
441
+ await client.request({ path: '/', method: 'GET' })
279
442
  } catch (error) {
280
443
  console.error(error.message)
444
+ } finally {
281
445
  client.close()
282
446
  server.close()
283
447
  }
@@ -285,16 +449,19 @@ try {
285
449
 
286
450
  ### Event: `'drain'`
287
451
 
288
- Emitted when pipeline is no longer busy.
452
+ <!-- YAML
453
+ added: v1.0.0
454
+ -->
289
455
 
290
- See [Dispatcher Event: `'drain'`](/docs/docs/api/Dispatcher.md#event-drain).
456
+ * `origin` {URL}
291
457
 
292
- #### Example - Client drain event
458
+ Emitted when the pipeline is no longer busy. See
459
+ [`Dispatcher` Event: `'drain'`][].
293
460
 
294
- ```js
295
- import { createServer } from 'http'
461
+ ```mjs
462
+ import { createServer } from 'node:http'
296
463
  import { Client } from 'undici'
297
- import { once } from 'events'
464
+ import { once } from 'node:events'
298
465
 
299
466
  const server = createServer((request, response) => {
300
467
  response.end('Hello, World!')
@@ -310,17 +477,40 @@ client.on('drain', () => {
310
477
  server.close()
311
478
  })
312
479
 
313
- const requests = [
480
+ await Promise.all([
314
481
  client.request({ path: '/', method: 'GET' }),
315
482
  client.request({ path: '/', method: 'GET' }),
316
483
  client.request({ path: '/', method: 'GET' })
317
- ]
318
-
319
- await Promise.all(requests)
320
-
321
- console.log('requests completed')
484
+ ])
322
485
  ```
323
486
 
324
487
  ### Event: `'error'`
325
488
 
326
- Invoked for user errors such as throwing in the `onResponseError` handler.
489
+ <!-- YAML
490
+ added: v1.0.0
491
+ -->
492
+
493
+ * `error` {Error}
494
+
495
+ Emitted for user errors, such as throwing inside an `onResponseError` handler.
496
+
497
+ [RFC 7230, section 6.3.2]: https://tools.ietf.org/html/rfc7230#section-6.3.2
498
+ [RFC 8305]: https://tools.ietf.org/html/rfc8305#section-5
499
+ [`Agent`]: Agent.md#class-agent
500
+ [`ClientStats`]: ClientStats.md
501
+ [`Connector`]: Connector.md
502
+ [`Dispatcher` Event: `'connect'`]: Dispatcher.md#event-connect
503
+ [`Dispatcher` Event: `'disconnect'`]: Dispatcher.md#event-disconnect
504
+ [`Dispatcher` Event: `'drain'`]: Dispatcher.md#event-drain
505
+ [`Dispatcher`]: Dispatcher.md#class-dispatcher
506
+ [`Pool`]: Pool.md#class-pool
507
+ [`buildConnector`]: Connector.md
508
+ [`dispatcher.close([callback])`]: Dispatcher.md#dispatcherclosecallback
509
+ [`dispatcher.connect()`]: Dispatcher.md#dispatcherconnectoptions-callback
510
+ [`dispatcher.destroy([error[, callback]])`]: Dispatcher.md#dispatcherdestroyerror-callback
511
+ [`dispatcher.dispatch(options, handler)`]: Dispatcher.md#dispatcherdispatchoptions-handler
512
+ [`dispatcher.pipeline(options, handler)`]: Dispatcher.md#dispatcherpipelineoptions-handler
513
+ [`dispatcher.request(options[, callback])`]: Dispatcher.md#dispatcherrequestoptions-callback
514
+ [`dispatcher.stream(options, factory[, callback])`]: Dispatcher.md#dispatcherstreamoptions-factory-callback
515
+ [`dispatcher.upgrade(options[, callback])`]: Dispatcher.md#dispatcherupgradeoptions-callback
516
+ [`tls.connect()`]: https://nodejs.org/api/tls.html#tlsconnectoptions-callback