Skip to content

Commit

Permalink
send an empty payload for NO_STATUS_RCVD
Browse files Browse the repository at this point in the history
  • Loading branch information
mhils authored and pgjones committed Aug 23, 2022
1 parent b0efe55 commit ec8596f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Expand Up @@ -4,6 +4,8 @@ Release History
Unreleased
----------

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


Expand Down
2 changes: 2 additions & 0 deletions src/wsproto/frame_protocol.py
Expand Up @@ -569,6 +569,8 @@ def received_frames(self) -> Generator[Frame, None, None]:

def close(self, code: Optional[int] = None, reason: Optional[str] = None) -> bytes:
payload = bytearray()
if code is CloseReason.NO_STATUS_RCVD:
code = None
if code is None and reason is not None:
raise TypeError("cannot specify a reason without a code")
if code in LOCAL_ONLY_CLOSE_REASONS:
Expand Down
7 changes: 6 additions & 1 deletion test/test_frame_protocol.py
Expand Up @@ -1036,9 +1036,14 @@ def test_reasoned_but_uncoded_close(self) -> None:
with pytest.raises(TypeError):
proto.close(reason="termites")

def test_local_only_close_reason(self) -> None:
def test_no_status_rcvd_close_reason(self) -> None:
proto = fp.FrameProtocol(client=False, extensions=[])
data = proto.close(code=fp.CloseReason.NO_STATUS_RCVD)
assert data == b"\x88\x00"

def test_local_only_close_reason(self) -> None:
proto = fp.FrameProtocol(client=False, extensions=[])
data = proto.close(code=fp.CloseReason.ABNORMAL_CLOSURE)
assert data == b"\x88\x02\x03\xe8"

def test_ping_without_payload(self) -> None:
Expand Down

0 comments on commit ec8596f

Please sign in to comment.