improve websocket frame masking api

This commit is contained in:
Thomas Kriechbaumer 2018-06-11 13:24:08 +02:00
parent 9047c4f2a5
commit be26958ea8
3 changed files with 2 additions and 8 deletions

View File

@ -71,7 +71,7 @@ class FrameHeader:
else:
self.length_code = length_code
if mask is DEFAULT and masking_key is DEFAULT:
if (mask is DEFAULT and masking_key is DEFAULT) or mask == 0 or mask is False:
self.mask = False
self.masking_key = b""
elif mask is DEFAULT:

View File

@ -122,7 +122,7 @@ class TestFrameHeader:
f = websockets.FrameHeader(masking_key=b"foob", mask=0)
assert not f.mask
assert f.masking_key
assert not f.masking_key
class TestFrame:

View File

@ -123,12 +123,6 @@ class TestWebsocketFrame:
assert not frm.header.mask
assert not frm.header.masking_key
frm = self.fr("wf:b'foo':-mask:k'abcd'", is_client=True)
assert not frm.header.mask
# We're reading back a corrupted frame - the first 3 characters of the
# mask is mis-interpreted as the payload
assert frm.payload == b"abc"
def test_knone(self):
with pytest.raises(Exception, match="Expected 4 bytes"):
self.fr("wf:b'foo':mask:knone")