Skip to content

Commit

Permalink
feat(ext/websocket): allow HTTP(S) protocol in URL (denoland#19862)
Browse files Browse the repository at this point in the history
  • Loading branch information
crowlKats authored Jul 28, 2023
1 parent fa52b5e commit cbfa98e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 8 additions & 1 deletion ext/websocket/01_websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.",
Expand Down
5 changes: 4 additions & 1 deletion tools/wpt/expectation.json
Original file line number Diff line number Diff line change
Expand Up @@ -7229,7 +7229,10 @@
"remove-own-iframe-during-onerror.window.html": false,
"remove-own-iframe-during-onerror.window.html?wpt_flags=h2": false,
"remove-own-iframe-during-onerror.window.html?wss": false,
"Create-on-worker-shutdown.any.worker.html": false
"Create-on-worker-shutdown.any.worker.html": false,
"Create-http-urls.any.html": true,
"Create-invalid-urls.any.html": true,
"Create-non-absolute-url.any.html": true
},
"workers": {
"Worker-base64.any.worker.html": true,
Expand Down

0 comments on commit cbfa98e

Please sign in to comment.