Skip to content

Commit ec8596f

Browse files
mhilspgjones
authored andcommitted
send an empty payload for NO_STATUS_RCVD
1 parent b0efe55 commit ec8596f

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

CHANGELOG.rst

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Release History
44
Unreleased
55
----------
66

7+
- Bugfix: When a close frame with status NO_STATUS_RCVD is sent, send
8+
and empty payload.
79
- <ToDo: add new entries here>
810

911

src/wsproto/frame_protocol.py

+2
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,8 @@ def received_frames(self) -> Generator[Frame, None, None]:
569569

570570
def close(self, code: Optional[int] = None, reason: Optional[str] = None) -> bytes:
571571
payload = bytearray()
572+
if code is CloseReason.NO_STATUS_RCVD:
573+
code = None
572574
if code is None and reason is not None:
573575
raise TypeError("cannot specify a reason without a code")
574576
if code in LOCAL_ONLY_CLOSE_REASONS:

test/test_frame_protocol.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1036,9 +1036,14 @@ def test_reasoned_but_uncoded_close(self) -> None:
10361036
with pytest.raises(TypeError):
10371037
proto.close(reason="termites")
10381038

1039-
def test_local_only_close_reason(self) -> None:
1039+
def test_no_status_rcvd_close_reason(self) -> None:
10401040
proto = fp.FrameProtocol(client=False, extensions=[])
10411041
data = proto.close(code=fp.CloseReason.NO_STATUS_RCVD)
1042+
assert data == b"\x88\x00"
1043+
1044+
def test_local_only_close_reason(self) -> None:
1045+
proto = fp.FrameProtocol(client=False, extensions=[])
1046+
data = proto.close(code=fp.CloseReason.ABNORMAL_CLOSURE)
10421047
assert data == b"\x88\x02\x03\xe8"
10431048

10441049
def test_ping_without_payload(self) -> None:

0 commit comments

Comments
 (0)