1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-25 00:29:09 -05:00

feat(ext/websocket): allow HTTP(S) protocol in URL (#19862)

Closes #19093
This commit is contained in:
Leo Kettmeir 2023-07-28 08:29:41 +02:00 committed by GitHub
parent fa52b5e733
commit cbfa98ea0b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 2 deletions

View file

@ -19,6 +19,7 @@ import {
MessageEvent, MessageEvent,
} from "ext:deno_web/02_event.js"; } from "ext:deno_web/02_event.js";
import { Blob, BlobPrototype } from "ext:deno_web/09_file.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 primordials = globalThis.__bootstrap.primordials;
const { const {
ArrayBufferPrototype, ArrayBufferPrototype,
@ -143,11 +144,17 @@ class WebSocket extends EventTarget {
let wsURL; let wsURL;
try { try {
wsURL = new URL(url); wsURL = new URL(url, getLocationHref());
} catch (e) { } catch (e) {
throw new DOMException(e.message, "SyntaxError"); 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:") { if (wsURL.protocol !== "ws:" && wsURL.protocol !== "wss:") {
throw new DOMException( throw new DOMException(
"Only ws & wss schemes are allowed in a WebSocket URL.", "Only ws & wss schemes are allowed in a WebSocket URL.",

View file

@ -7229,7 +7229,10 @@
"remove-own-iframe-during-onerror.window.html": false, "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?wpt_flags=h2": false,
"remove-own-iframe-during-onerror.window.html?wss": 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": { "workers": {
"Worker-base64.any.worker.html": true, "Worker-base64.any.worker.html": true,