aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/websockets.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2015-04-24 15:31:14 +1200
committerAldo Cortesi <aldo@nullcube.com>2015-04-24 15:31:14 +1200
commit192fd1db7f233b71398c5255cbdebe1928768b55 (patch)
tree3a134ada227f00777cb9b05b5bf1cc102a3fc729 /netlib/websockets.py
parentdef93ea8cae69676a91b01e149e8a406fa03eacd (diff)
downloadmitmproxy-192fd1db7f233b71398c5255cbdebe1928768b55.tar.gz
mitmproxy-192fd1db7f233b71398c5255cbdebe1928768b55.tar.bz2
mitmproxy-192fd1db7f233b71398c5255cbdebe1928768b55.zip
websockets: include all header values in frame roundtrip
Diffstat (limited to 'netlib/websockets.py')
-rw-r--r--netlib/websockets.py27
1 files changed, 15 insertions, 12 deletions
diff --git a/netlib/websockets.py b/netlib/websockets.py
index b1afa620..85aad9c6 100644
--- a/netlib/websockets.py
+++ b/netlib/websockets.py
@@ -159,7 +159,7 @@ class FrameHeader:
else:
mask = self.mask
- second_byte = (mask << 7) | length_code
+ second_byte = utils.setbit(length_code, 7, mask)
b = chr(first_byte) + chr(second_byte)
@@ -189,10 +189,9 @@ class FrameHeader:
rsv1 = utils.getbit(first_byte, 6)
rsv2 = utils.getbit(first_byte, 5)
rsv3 = utils.getbit(first_byte, 4)
- # grab right most 4 bits by and-ing with 00001111
+ # grab right-most 4 bits
opcode = first_byte & 15
- # grab left most bit
- mask_bit = second_byte >> 7
+ mask_bit = utils.getbit(second_byte, 7)
# grab the next 7 bits
length_code = second_byte & 127
@@ -279,6 +278,14 @@ class Frame(object):
masking_key = masking_key,
)
+ @classmethod
+ def from_bytes(cls, bytestring):
+ """
+ Construct a websocket frame from an in-memory bytestring
+ to construct a frame from a stream of bytes, use from_file() directly
+ """
+ return cls.from_file(io.BytesIO(bytestring))
+
def human_readable(self):
return "\n".join([
("fin - " + str(self.header.fin)),
@@ -292,14 +299,6 @@ class Frame(object):
("payload - " + repr(str(self.payload))),
])
- @classmethod
- def from_bytes(cls, bytestring):
- """
- Construct a websocket frame from an in-memory bytestring
- to construct a frame from a stream of bytes, use from_file() directly
- """
- return cls.from_file(io.BytesIO(bytestring))
-
def to_bytes(self):
"""
Serialize the frame back into the wire format, returns a bytestring
@@ -338,6 +337,10 @@ class Frame(object):
mask = header.mask,
payload_length = header.payload_length,
masking_key = header.masking_key,
+ rsv1 = header.rsv1,
+ rsv2 = header.rsv2,
+ rsv3 = header.rsv3,
+ length_code = header.length_code
)
def __eq__(self, other):