denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
95.28k stars 5.28k forks source link

Accept `Deno.HttpClient` instance for WebSocketStream API #11846

Open danopia opened 3 years ago

danopia commented 3 years ago

The options bag accepted by WebSocketStream should be extended to accept a Deno.HttpClient object. This would enable trusting specific TLS server certificates, and also Mutual TLS / Client Certificate support. There's also a proxy field in Deno.CreateHttpClientOptions which presumably also applies to WebSockets.

For context, both APIs here are currently unstable in Deno. The upstream WebSocketStream spec does not allow for customizing TLS as it is intended for a web browser context, like fetch.

Brief example code:

const client = Deno.createHttpClient({
  caData: await Deno.readTextFile("./ca.pem"),
});

const ws = new WebSocketStream("https://myserver.com", { client });
okikio-school commented 1 year ago

Is this something Deno is interested in supporting? cc @lucacasonato

danopia commented 1 year ago

I'm still looking for TLS abilities on WebSockets to match the TLS abilities of fetch() :) Kubernetes loves network certificates