Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(extensions/websocket): implement websocketstream #10365

Merged
merged 77 commits into from
Aug 9, 2021
Merged
Show file tree
Hide file tree
Changes from 69 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
c571f8f
implement
crowlKats Apr 25, 2021
71eb7d7
fiix
crowlKats Apr 25, 2021
03db16b
fiix
crowlKats Apr 25, 2021
0f34ea5
Merge branch 'main' into websocketstream
crowlKats Apr 30, 2021
cfa0ef9
better errors
crowlKats Apr 30, 2021
ff6f1df
Merge branch 'main' into websocketstream
ry May 1, 2021
bd2ae46
Merge branch 'main' into websocketstream
crowlKats May 1, 2021
3364f0c
webidl
crowlKats May 1, 2021
501262b
lint
crowlKats May 1, 2021
a518f43
fix idl
crowlKats May 1, 2021
9660661
add tests
crowlKats May 1, 2021
e70a25d
clean up
crowlKats May 2, 2021
30df21f
Update extensions/websocket/02_websocketstream.js
crowlKats May 3, 2021
fa9fd0f
clean up
crowlKats May 3, 2021
358ea94
throw TypeError for invalid chunk type
crowlKats May 3, 2021
db5d42f
Update extensions/websocket/02_websocketstream.js
crowlKats May 3, 2021
ec1fbe8
fix
crowlKats May 3, 2021
3b28892
Update extensions/websocket/02_websocketstream.js
crowlKats May 3, 2021
c842e0e
Merge remote-tracking branch 'origin/main' into websocketstream
piscisaureus May 4, 2021
4aaae1b
lint ignore no-undef
crowlKats May 4, 2021
40f1325
move type declaration
crowlKats May 4, 2021
e522db8
Revert "move type declaration"
crowlKats May 4, 2021
c382f52
Merge branch 'main' into websocketstream
crowlKats May 11, 2021
aa04087
partial wpt conformance
crowlKats May 11, 2021
7627a41
more wpt
crowlKats May 11, 2021
ba5f7b6
clean up
crowlKats May 11, 2021
2ca5d8b
Merge branch 'main' into websocketstream
crowlKats May 19, 2021
6ab0832
update expectation.json
crowlKats May 19, 2021
0b85846
remove no-undef directive
crowlKats May 20, 2021
c263437
remove unneeded tests
crowlKats May 20, 2021
6580940
custominspect
crowlKats May 20, 2021
f881abd
Merge branch 'main' into websocketstream
crowlKats May 25, 2021
82bcfd7
fix hanging
crowlKats May 25, 2021
c0060b3
Merge branch 'main' into websocketstream
crowlKats Jun 16, 2021
05667b4
fix
crowlKats Jun 16, 2021
141fca5
fix wpt
crowlKats Jun 17, 2021
a500487
Merge branch 'main' into websocketstream
crowlKats Jul 8, 2021
f6a38aa
fix
crowlKats Jul 8, 2021
9fe67ec
fix constructor wpt
crowlKats Jul 8, 2021
bd4cfba
fmt
crowlKats Jul 8, 2021
4da878d
proper abort
crowlKats Jul 9, 2021
cff8448
fix
crowlKats Jul 9, 2021
b4bf49e
fix abort
crowlKats Jul 9, 2021
c90e243
clean up
crowlKats Jul 10, 2021
d3ebda7
fmt
crowlKats Jul 10, 2021
be2701a
revert early close
crowlKats Jul 10, 2021
f8f3062
lint
crowlKats Jul 10, 2021
1056d70
handle early close
crowlKats Jul 10, 2021
0930f9d
handle early close
crowlKats Jul 10, 2021
35ec1ef
more wpt
crowlKats Jul 10, 2021
2666a08
fix wpt
crowlKats Jul 10, 2021
63d6f52
lint
crowlKats Jul 10, 2021
b0c9c41
fmt
crowlKats Jul 10, 2021
c0b5a48
primordials
littledivy Jul 10, 2021
f5dc1e9
Update extensions/websocket/02_websocketstream.js
crowlKats Jul 10, 2021
5c7745d
Merge branch 'main' into websocketstream
crowlKats Jul 12, 2021
aff900a
fix leaking
crowlKats Jul 12, 2021
a212a71
fix various issues
crowlKats Jul 12, 2021
b081843
fmt
crowlKats Jul 12, 2021
ceff648
lint
crowlKats Jul 12, 2021
1eb23fe
Merge branch 'main' into websocketstream
crowlKats Jul 19, 2021
1ef1633
fix
crowlKats Jul 19, 2021
d2a9e86
ci
crowlKats Jul 19, 2021
a3844bf
fix
crowlKats Jul 19, 2021
6aa7957
fix
crowlKats Jul 19, 2021
8fade20
fix
crowlKats Jul 26, 2021
09f2dde
Merge branch 'main' into websocketstream
bartlomieju Jul 29, 2021
f5c46c8
Merge branch 'main' into websocketstream
bartlomieju Aug 2, 2021
1e0f29b
Merge branch 'main' into websocketstream
bartlomieju Aug 6, 2021
57c12b9
Update extensions/websocket/02_websocketstream.js
crowlKats Aug 8, 2021
198710b
add branding
crowlKats Aug 8, 2021
35db598
use internal abort methods
crowlKats Aug 8, 2021
5abd0bb
Merge remote-tracking branch 'origin/websocketstream' into websockets…
crowlKats Aug 8, 2021
67c25c5
Merge branch 'main' into websocketstream
lucacasonato Aug 9, 2021
f8bbe00
Merge remote-tracking branch 'origin/main' into websocketstream
lucacasonato Aug 9, 2021
1c80cb0
fix build
lucacasonato Aug 9, 2021
4c5f5b2
make WebSocketStream unstable
lucacasonato Aug 9, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions cli/dts/lib.deno.unstable.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1144,3 +1144,28 @@ declare interface WorkerOptions {
};
};
}

declare interface WebSocketStreamOptions {
protocols?: string[];
crowlKats marked this conversation as resolved.
Show resolved Hide resolved
crowlKats marked this conversation as resolved.
Show resolved Hide resolved
signal?: AbortSignal;
}

declare interface WebSocketConnection {
readable: ReadableStream<string | Uint8Array>;
writable: WritableStream<string | Uint8Array>;
extensions: string;
protocol: string;
}

declare interface WebSocketCloseInfo {
code?: number;
crowlKats marked this conversation as resolved.
Show resolved Hide resolved
reason?: string;
}

declare class WebSocketStream {
constructor(url: string, options?: WebSocketStreamOptions);
url: string;
connection: Promise<WebSocketConnection>;
closed: Promise<WebSocketCloseInfo>;
close(closeInfo?: WebSocketCloseInfo): void;
}
21 changes: 21 additions & 0 deletions cli/tests/integration/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,27 @@ fn websocket() {
assert!(status.success());
}

#[test]
fn websocketstream() {
let _g = util::http_server();

let script = util::tests_path().join("websocketstream_test.ts");
let root_ca = util::tests_path().join("tls/RootCA.pem");
let status = util::deno_cmd()
.arg("test")
.arg("--unstable")
.arg("--allow-net")
.arg("--cert")
.arg(root_ca)
.arg(script)
.spawn()
.unwrap()
.wait()
.unwrap();

assert!(status.success());
}

#[cfg(not(windows))]
#[test]
fn set_raw_should_not_panic_on_no_tty() {
Expand Down
82 changes: 82 additions & 0 deletions cli/tests/websocketstream_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright 2018-2021 the Deno authors. All rights reserved. MIT license.

import {
assertEquals,
assertThrows,
assertThrowsAsync,
} from "../../test_util/std/testing/asserts.ts";

Deno.test("fragment", () => {
assertThrows(() => new WebSocketStream("ws://localhost:4242/#"));
assertThrows(() => new WebSocketStream("ws://localhost:4242/#foo"));
});

Deno.test("duplicate protocols", () => {
assertThrows(() =>
new WebSocketStream("ws://localhost:4242", {
protocols: ["foo", "foo"],
})
);
});

Deno.test("connect & close custom valid code", async () => {
const ws = new WebSocketStream("ws://localhost:4242");
await ws.connection;
ws.close({ code: 1000 });
await ws.closed;
});

Deno.test("connect & close custom invalid reason", async () => {
const ws = new WebSocketStream("ws://localhost:4242");
await ws.connection;
assertThrows(() => ws.close({ code: 1000, reason: "".padEnd(124, "o") }));
ws.close();
await ws.closed;
});

Deno.test("echo string", async () => {
const ws = new WebSocketStream("ws://localhost:4242");
const { readable, writable } = await ws.connection;
await writable.getWriter().write("foo");
const res = await readable.getReader().read();
crowlKats marked this conversation as resolved.
Show resolved Hide resolved
assertEquals(res.value, "foo");
ws.close();
await ws.closed;
});

Deno.test("echo string tls", async () => {
const ws = new WebSocketStream("wss://localhost:4243");
const { readable, writable } = await ws.connection;
await writable.getWriter().write("foo");
const res = await readable.getReader().read();
assertEquals(res.value, "foo");
ws.close();
await ws.closed;
});

Deno.test("websocket error", async () => {
const ws = new WebSocketStream("wss://localhost:4242");
await Promise.all([
assertThrowsAsync(
() => ws.connection,
Deno.errors.UnexpectedEof,
"tls handshake eof",
),
assertThrowsAsync(
() => ws.closed,
Deno.errors.UnexpectedEof,
"tls handshake eof",
),
]);
});

Deno.test("echo uint8array", async () => {
const ws = new WebSocketStream("ws://localhost:4242");
const { readable, writable } = await ws.connection;
const uint = new Uint8Array([102, 111, 111]);
await writable.getWriter().write(uint);
const res = await readable.getReader().read();
assertEquals(res.value, uint);
ws.close();
await ws.closed;
});
2 changes: 2 additions & 0 deletions extensions/web/06_streams.js
Original file line number Diff line number Diff line change
Expand Up @@ -4455,6 +4455,8 @@
isReadableStreamDisturbed,
errorReadableStream,
createProxy,
writableStreamClose,
Deferred,
// Exposed in global runtime scope
ByteLengthQueuingStrategy,
CountQueuingStrategy,
Expand Down
6 changes: 5 additions & 1 deletion extensions/websocket/01_websocket.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,11 @@

this[_url] = wsURL.href;

core.opSync("op_ws_check_permission", this[_url]);
core.opSync(
"op_ws_check_permission_and_cancel_handle",
this[_url],
false,
);

if (typeof protocols === "string") {
protocols = [protocols];
Expand Down
Loading