diff options
author | Yusuke Sakurai <kerokerokerop@gmail.com> | 2019-09-29 01:46:21 +0900 |
---|---|---|
committer | Ryan Dahl <ry@tinyclouds.org> | 2019-09-28 12:46:21 -0400 |
commit | 3cba0a4f4ac601a7039b0a1e40dd42385f4a3bfb (patch) | |
tree | cb1e32546a87ccf58b12240704188e2b8a2d7064 /ws/mod.ts | |
parent | a472b6732dd37636b7b31128f53d3e6bcf531a73 (diff) |
feat: wss support with dialTLS (denoland/deno_std#615)
Original: https://github.com/denoland/deno_std/commit/cac2d5ee68332956e59f548ff08f73b0fadf83d1
Diffstat (limited to 'ws/mod.ts')
-rw-r--r-- | ws/mod.ts | 18 |
1 files changed, 10 insertions, 8 deletions
@@ -480,15 +480,17 @@ export async function connectWebSocket( headers: Headers = new Headers() ): Promise<WebSocket> { const url = new URL(endpoint); - let { hostname, port } = url; - if (!port) { - if (url.protocol === "http" || url.protocol === "ws") { - port = "80"; - } else if (url.protocol === "https" || url.protocol === "wss") { - throw new Error("currently https/wss is not supported"); - } + let { hostname } = url; + let conn: Conn; + if (url.protocol === "http:" || url.protocol === "ws:") { + const port = parseInt(url.port || "80"); + conn = await Deno.dial({ hostname, port }); + } else if (url.protocol === "https:" || url.protocol === "wss:") { + const port = parseInt(url.port || "443"); + conn = await Deno.dialTLS({ hostname, port }); + } else { + throw new Error("ws: unsupported protocol: " + url.protocol); } - const conn = await Deno.dial({ hostname, port: Number(port) }); const bufWriter = new BufWriter(conn); const bufReader = new BufReader(conn); try { |