Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/wsproto/frame_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ def close(self, code: Optional[int] = None, reason: Optional[str] = None) -> byt
if code is None and reason:
raise TypeError("cannot specify a reason without a code")
if code in LOCAL_ONLY_CLOSE_REASONS:
code = CloseReason.NORMAL_CLOSURE
raise ValueError(f"cannot specify a local-only close code, got {code}")
if code is not None:
payload += bytearray(struct.pack("!H", code))
if reason is not None:
Expand Down
4 changes: 2 additions & 2 deletions test/test_frame_protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,8 +1043,8 @@ def test_no_status_rcvd_close_reason(self) -> None:

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"
with pytest.raises(ValueError):
proto.close(code=fp.CloseReason.ABNORMAL_CLOSURE)

def test_ping_without_payload(self) -> None:
proto = fp.FrameProtocol(client=False, extensions=[])
Expand Down