Skip to content

Commit

Permalink
Correct generation of binary xhr2 packets
Browse files Browse the repository at this point in the history
  • Loading branch information
miguelgrinberg committed Mar 4, 2016
1 parent d338ee8 commit 5e5e0a3
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions engineio/payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ def encode(self, b64=False):
while packet_len != 0:
binary_len = six.int2byte(packet_len % 10) + binary_len
packet_len = int(packet_len / 10)
encoded_payload += b'\0' + binary_len + b'\xff' + \
encoded_packet
if not pkt.binary:
encoded_payload += b'\0'
else:
encoded_payload += b'\1'
encoded_payload += binary_len + b'\xff' + encoded_packet
return encoded_payload

def decode(self, encoded_payload):
Expand Down
2 changes: 1 addition & 1 deletion tests/test_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def test_encode_payload_xhr_binary(self):

def test_decode_payload_xhr_binary(self):
p = payload.Payload(encoded_payload=b'6:b4AAEC')
self.assertEqual(p.encode(), b'\x00\x04\xff\x04\x00\x01\x02')
self.assertEqual(p.encode(), b'\x01\x04\xff\x04\x00\x01\x02')

def test_decode_invalid_payload(self):
self.assertRaises(ValueError, payload.Payload,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ def test_connect_b64_with_0(self):
s.send('1', b'\x00\x01\x02', binary=True)
environ = {'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'sid=1&b64=0'}
r = s.handle_request(environ, start_response)
self.assertEqual(r[0], b'\x00\x04\xff\x04\x00\x01\x02')
self.assertEqual(r[0], b'\x01\x04\xff\x04\x00\x01\x02')

def test_connect_b64_with_false(self):
s = server.Server(allow_upgrades=False)
Expand All @@ -308,7 +308,7 @@ def test_connect_b64_with_false(self):
s.send('1', b'\x00\x01\x02', binary=True)
environ = {'REQUEST_METHOD': 'GET', 'QUERY_STRING': 'sid=1&b64=false'}
r = s.handle_request(environ, start_response)
self.assertEqual(r[0], b'\x00\x04\xff\x04\x00\x01\x02')
self.assertEqual(r[0], b'\x01\x04\xff\x04\x00\x01\x02')

def test_connect_custom_ping_times(self):
s = server.Server(ping_timeout=123, ping_interval=456)
Expand Down

0 comments on commit 5e5e0a3

Please sign in to comment.