mirror of
https://github.com/denoland/deno.git
synced 2025-10-02 15:14:33 +00:00
feat(ext/websocket): allow HTTP(S) protocol in URL (#19862)
Closes #19093
This commit is contained in:
parent
fa52b5e733
commit
cbfa98ea0b
2 changed files with 12 additions and 2 deletions
|
@ -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.",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue