feat(unstable): support Deno.HttpClient in WebSocket (#30692)
Some checks are pending
ci / build libs (push) Blocked by required conditions
ci / publish canary (push) Blocked by required conditions
ci / pre-build (push) Waiting to run
ci / test debug linux-aarch64 (push) Blocked by required conditions
ci / test release linux-aarch64 (push) Blocked by required conditions
ci / test debug macos-aarch64 (push) Blocked by required conditions
ci / test release macos-aarch64 (push) Blocked by required conditions
ci / bench release linux-x86_64 (push) Blocked by required conditions
ci / lint debug linux-x86_64 (push) Blocked by required conditions
ci / lint debug macos-x86_64 (push) Blocked by required conditions
ci / lint debug windows-x86_64 (push) Blocked by required conditions
ci / test debug linux-x86_64 (push) Blocked by required conditions
ci / test release linux-x86_64 (push) Blocked by required conditions
ci / test debug macos-x86_64 (push) Blocked by required conditions
ci / test release macos-x86_64 (push) Blocked by required conditions
ci / test debug windows-x86_64 (push) Blocked by required conditions
ci / test release windows-x86_64 (push) Blocked by required conditions

This commit adds support for specifying a `Deno.HttpClient` in the
`client` field of the `WebSocketOptions` bag. This mirrors how users
pass a custom HTTP client to `fetch`.

Additionally the underlying connection for websockets are now
established through the same mechanism used for `fetch`, which
means that `WebSocket` now correctly uses HTTP proxies, like
when configuring the `HTTP_PROXY` env var.

---------

Signed-off-by: Luca Casonato <hello@lcas.dev>
This commit is contained in:
Luca Casonato 2025-09-12 11:42:25 +02:00 committed by GitHub
parent 8244cd8e21
commit 97ae158610
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 464 additions and 224 deletions

View file

@ -307,6 +307,24 @@ interface WebSocketOptions {
* This feature is non-standard.
*/
headers?: HeadersInit;
/**
* An `HttpClient` instance to use when creating the WebSocket connection.
* This is useful when you need to connect through a proxy or customize TLS settings.
*
* ```ts
* const client = Deno.createHttpClient({
* proxy: {
* transport: "unix",
* path: "/path/to/socket",
* },
* });
*
* const ws = new WebSocket("ws://localhost:8000/socket", { client });
* ```
*
* @experimental
*/
client?: Deno.HttpClient;
}
/**