mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
revert websocket changes from 73586b1b
The DEFAULT construct is very weird, but with None we apparently break pathod in some difficult-to-debug ways. Revisit once we do more here.
This commit is contained in:
parent
21579f0add
commit
9fbeac50ce
@ -14,6 +14,8 @@ from netlib import utils
|
|||||||
MAX_16_BIT_INT = (1 << 16)
|
MAX_16_BIT_INT = (1 << 16)
|
||||||
MAX_64_BIT_INT = (1 << 64)
|
MAX_64_BIT_INT = (1 << 64)
|
||||||
|
|
||||||
|
DEFAULT=object()
|
||||||
|
|
||||||
OPCODE = utils.BiDi(
|
OPCODE = utils.BiDi(
|
||||||
CONTINUE=0x00,
|
CONTINUE=0x00,
|
||||||
TEXT=0x01,
|
TEXT=0x01,
|
||||||
@ -34,9 +36,9 @@ class FrameHeader(object):
|
|||||||
rsv1=False,
|
rsv1=False,
|
||||||
rsv2=False,
|
rsv2=False,
|
||||||
rsv3=False,
|
rsv3=False,
|
||||||
masking_key=None,
|
masking_key=DEFAULT,
|
||||||
mask=None,
|
mask=DEFAULT,
|
||||||
length_code=None
|
length_code=DEFAULT
|
||||||
):
|
):
|
||||||
if not 0 <= opcode < 2 ** 4:
|
if not 0 <= opcode < 2 ** 4:
|
||||||
raise ValueError("opcode must be 0-16")
|
raise ValueError("opcode must be 0-16")
|
||||||
@ -47,18 +49,18 @@ class FrameHeader(object):
|
|||||||
self.rsv2 = rsv2
|
self.rsv2 = rsv2
|
||||||
self.rsv3 = rsv3
|
self.rsv3 = rsv3
|
||||||
|
|
||||||
if length_code is None:
|
if length_code is DEFAULT:
|
||||||
self.length_code = self._make_length_code(self.payload_length)
|
self.length_code = self._make_length_code(self.payload_length)
|
||||||
else:
|
else:
|
||||||
self.length_code = length_code
|
self.length_code = length_code
|
||||||
|
|
||||||
if mask is None and masking_key is None:
|
if mask is DEFAULT and masking_key is DEFAULT:
|
||||||
self.mask = False
|
self.mask = False
|
||||||
self.masking_key = b""
|
self.masking_key = b""
|
||||||
elif mask is None:
|
elif mask is DEFAULT:
|
||||||
self.mask = 1
|
self.mask = 1
|
||||||
self.masking_key = masking_key
|
self.masking_key = masking_key
|
||||||
elif masking_key is None:
|
elif masking_key is DEFAULT:
|
||||||
self.mask = mask
|
self.mask = mask
|
||||||
self.masking_key = os.urandom(4)
|
self.masking_key = os.urandom(4)
|
||||||
else:
|
else:
|
||||||
@ -166,7 +168,7 @@ class FrameHeader(object):
|
|||||||
if mask_bit == 1:
|
if mask_bit == 1:
|
||||||
masking_key = fp.safe_read(4)
|
masking_key = fp.safe_read(4)
|
||||||
else:
|
else:
|
||||||
masking_key = False
|
masking_key = None
|
||||||
|
|
||||||
return cls(
|
return cls(
|
||||||
fin=fin,
|
fin=fin,
|
||||||
@ -230,7 +232,7 @@ class Frame(object):
|
|||||||
masking_key = os.urandom(4)
|
masking_key = os.urandom(4)
|
||||||
else:
|
else:
|
||||||
mask_bit = 0
|
mask_bit = 0
|
||||||
masking_key = False
|
masking_key = None
|
||||||
|
|
||||||
return cls(
|
return cls(
|
||||||
message,
|
message,
|
||||||
@ -311,4 +313,4 @@ class Frame(object):
|
|||||||
def __eq__(self, other):
|
def __eq__(self, other):
|
||||||
if isinstance(other, Frame):
|
if isinstance(other, Frame):
|
||||||
return bytes(self) == bytes(other)
|
return bytes(self) == bytes(other)
|
||||||
return False
|
return False
|
||||||
|
Loading…
Reference in New Issue
Block a user