mirror of
https://github.com/denoland/deno.git
synced 2025-01-09 23:58:23 -05:00
fix(ext/websocket): Fix close code without reason (#27578)
Fixes https://github.com/denoland/deno/issues/27566 The close code wasn't sent if reason was None, defaulting to 1005. This patch allows sending close code without reason.
This commit is contained in:
parent
1661ddd9ca
commit
e233173653
3 changed files with 9 additions and 4 deletions
|
@ -758,9 +758,14 @@ pub async fn op_ws_close(
|
|||
return Ok(());
|
||||
};
|
||||
|
||||
const EMPTY_PAYLOAD: &[u8] = &[];
|
||||
|
||||
let frame = reason
|
||||
.map(|reason| Frame::close(code.unwrap_or(1005), reason.as_bytes()))
|
||||
.unwrap_or_else(|| Frame::close_raw(vec![].into()));
|
||||
.unwrap_or_else(|| match code {
|
||||
Some(code) => Frame::close(code, EMPTY_PAYLOAD),
|
||||
_ => Frame::close_raw(EMPTY_PAYLOAD.into()),
|
||||
});
|
||||
|
||||
resource.closed.set(true);
|
||||
let lock = resource.reserve_lock();
|
||||
|
|
|
@ -2663,7 +2663,6 @@ async fn websocket_server_multi_field_connection_header() {
|
|||
|
||||
let message = socket.read_frame().await.unwrap();
|
||||
assert_eq!(message.opcode, fastwebsockets::OpCode::Close);
|
||||
assert!(message.payload.is_empty());
|
||||
socket
|
||||
.write_frame(fastwebsockets::Frame::close_raw(vec![].into()))
|
||||
.await
|
||||
|
|
|
@ -262,7 +262,7 @@ Deno.test({
|
|||
socket.onopen = () => socket.send("Hello");
|
||||
socket.onmessage = () => {
|
||||
socket.send("Bye");
|
||||
socket.close();
|
||||
socket.close(1000);
|
||||
};
|
||||
socket.onclose = () => ac.abort();
|
||||
socket.onerror = () => fail();
|
||||
|
@ -288,7 +288,8 @@ Deno.test({
|
|||
seenBye = true;
|
||||
}
|
||||
};
|
||||
ws.onclose = () => {
|
||||
ws.onclose = (e) => {
|
||||
assertEquals(e.code, 1000);
|
||||
deferred.resolve();
|
||||
};
|
||||
await Promise.all([deferred.promise, server.finished]);
|
||||
|
|
Loading…
Reference in a new issue