You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: deps/undici/src/docs/docs/api/Client.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -29,7 +29,7 @@ Returns: `Client`
29
29
***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.
30
30
***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.
31
31
***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.
32
-
***allowH2**: `boolean` - Default: `false`. Enables support for H2 if the server has assigned bigger priority to it through ALPN negotiation.
32
+
***allowH2**: `boolean` - Default: `true`. Enables support for H2 if the server has assigned bigger priority to it through ALPN negotiation.
33
33
***useH2c**: `boolean` - Default: `false`. Enforces h2c for non-https connections.
34
34
***maxConcurrentStreams**: `number` - Default: `100`. Dictates the maximum number of concurrent streams for a single H2 session. It can be overridden by a SETTINGS remote frame.
35
35
***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.
The `handshakeResponse` object contains the HTTP response that upgraded the connection to WebSocket:
193
+
The `handshakeResponse` object contains the HTTP response that established the WebSocket connection:
194
194
195
-
-`status` (number): The HTTP status code (101 for successful WebSocket upgrade)
196
-
-`statusText` (string): The HTTP status message ('Switching Protocols' for successful upgrade)
195
+
-`status` (number): The HTTP status code (`101` for HTTP/1.1 upgrade, `200` for HTTP/2 extended CONNECT)
196
+
-`statusText` (string): The HTTP status message (`'Switching Protocols'` for HTTP/1.1, commonly `'OK'` for HTTP/2 in Node.js)
197
197
-`headers` (object): The HTTP response headers from the server, including:
198
+
-`sec-websocket-accept` and other WebSocket-related headers
198
199
-`upgrade: 'websocket'`
199
200
-`connection: 'upgrade'`
200
-
-`sec-websocket-accept` and other WebSocket-related headers
201
+
202
+
The `upgrade` and `connection` headers are only present for HTTP/1.1 handshakes.
201
203
202
204
This information is particularly useful for debugging and monitoring WebSocket connections, as it provides access to the initial HTTP handshake response that established the WebSocket connection.
Copy file name to clipboardExpand all lines: deps/undici/src/docs/docs/api/Dispatcher.md
+62-27Lines changed: 62 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -212,6 +212,41 @@ Returns: `Boolean` - `false` if dispatcher is busy and further dispatch calls wo
212
212
***onResponseEnd**`(controller: DispatchController, trailers: Record<string, string | string[]>) => void` - Invoked when response payload and trailers have been received and the request has completed. Not required for `upgrade` requests.
213
213
***onResponseError**`(controller: DispatchController, error: Error) => void` - Invoked when an error has occurred. May not throw.
214
214
215
+
#### Migration from legacy handler API
216
+
217
+
If you were previously using `onConnect/onHeaders/onData/onComplete/onError`, switch to the new callbacks:
218
+
219
+
-`onConnect(abort)` → `onRequestStart(controller)` and call `controller.abort(reason)`
To access raw header arrays (for preserving duplicates/casing), read them from the controller:
227
+
228
+
-`controller.rawHeaders` for response headers
229
+
-`controller.rawTrailers` for trailers
230
+
231
+
Pause/resume now uses the controller:
232
+
233
+
- Call `controller.pause()` and `controller.resume()` instead of returning `false` from handlers.
234
+
235
+
#### Compatibility notes
236
+
237
+
Undici now stores the global dispatcher under `Symbol.for('undici.globalDispatcher.2')`.
238
+
This avoids conflicts with runtimes (such as Node.js built-in `fetch`) that still rely on the legacy dispatcher handler interface.
239
+
240
+
`setGlobalDispatcher()` also mirrors the configured dispatcher to `Symbol.for('undici.globalDispatcher.1')` using a `Dispatcher1Wrapper`, so Node's built-in `fetch` can keep using the legacy handler contract.
241
+
242
+
If you need to expose a new dispatcher/agent to legacy v1 handler consumers (`onConnect/onHeaders/onData/onComplete/onError/onUpgrade`), use `Dispatcher1Wrapper`:
For easy use with [stream.pipeline](https://nodejs.org/api/stream.html#stream_stream_pipeline_source_transforms_destination_callback). The `handler` argument should return a `Readable` from which the result will be read. Usually it should just return the `body` argument unless some kind of transformation needs to be performed based on e.g. `headers` or `statusCode`. The `handler` should validate the response and save any required state. If there is an error, it should be thrown. The function returns a `Duplex` which writes to the request and reads from the response.
402
+
For easy use with [stream.pipeline](https://nodejs.org/api/stream.html#streampipelinesource-transforms-destination-options). The `handler` argument should return a `Readable` from which the result will be read. Usually it should just return the `body` argument unless some kind of transformation needs to be performed based on e.g. `headers` or `statusCode`. The `handler` should validate the response and save any required state. If there is an error, it should be thrown. The function returns a `Duplex` which writes to the request and reads from the response.
0 commit comments