summaryrefslogtreecommitdiff
path: root/ext/websocket/01_websocket.js
diff options
context:
space:
mode:
authorLeo Kettmeir <crowlkats@toaxl.com>2023-07-28 08:29:41 +0200
committerGitHub <noreply@github.com>2023-07-28 06:29:41 +0000
commitcbfa98ea0bf4ee994bf564671ece514eb4efae1f (patch)
tree667b9cdffed72b6f5083d3f8f0160965afa2a4b4 /ext/websocket/01_websocket.js
parentfa52b5e73374dfd1e76f82207dd59020b6520148 (diff)
feat(ext/websocket): allow HTTP(S) protocol in URL (#19862)
Closes #19093
Diffstat (limited to 'ext/websocket/01_websocket.js')
-rw-r--r--ext/websocket/01_websocket.js9
1 files changed, 8 insertions, 1 deletions
diff --git a/ext/websocket/01_websocket.js b/ext/websocket/01_websocket.js
index 635979174..3f4e16b90 100644
--- a/ext/websocket/01_websocket.js
+++ b/ext/websocket/01_websocket.js
@@ -19,6 +19,7 @@ import {
MessageEvent,
} from "ext:deno_web/02_event.js";
import { Blob, BlobPrototype } from "ext:deno_web/09_file.js";
+import { getLocationHref } from "ext:deno_web/12_location.js";
const primordials = globalThis.__bootstrap.primordials;
const {
ArrayBufferPrototype,
@@ -143,11 +144,17 @@ class WebSocket extends EventTarget {
let wsURL;
try {
- wsURL = new URL(url);
+ wsURL = new URL(url, getLocationHref());
} catch (e) {
throw new DOMException(e.message, "SyntaxError");
}
+ if (wsURL.protocol === "http:") {
+ wsURL.protocol = "ws:";
+ } else if (wsURL.protocol === "https:") {
+ wsURL.protocol = "wss:";
+ }
+
if (wsURL.protocol !== "ws:" && wsURL.protocol !== "wss:") {
throw new DOMException(
"Only ws & wss schemes are allowed in a WebSocket URL.",