websockets.py (1262:ba07e83ecf6f) websockets.py (1424:449e7e7d25c9)
1import re
2import random
3import base64
4import struct
5import select
6import hashlib
7import itertools
8from unit.applications.proto import TestApplicationProto

--- 38 unchanged lines hidden (view full) ---

47
48 _, sock = self.get(
49 headers=headers,
50 no_recv=True,
51 start=True,
52 )
53
54 resp = ''
1import re
2import random
3import base64
4import struct
5import select
6import hashlib
7import itertools
8from unit.applications.proto import TestApplicationProto

--- 38 unchanged lines hidden (view full) ---

47
48 _, sock = self.get(
49 headers=headers,
50 no_recv=True,
51 start=True,
52 )
53
54 resp = ''
55 while select.select([sock], [], [], 30)[0]:
55 while select.select([sock], [], [], 60)[0]:
56 resp += sock.recv(4096).decode()
57
58 if (
59 re.search('101 Switching Protocols', resp)
60 and resp[-4:] == '\r\n\r\n'
61 ):
62 resp = self._resp_to_dict(resp)
63 break
64
65 return (resp, sock, key)
66
67 def apply_mask(self, data, mask):
68 return bytes(b ^ m for b, m in zip(data, itertools.cycle(mask)))
69
70 def serialize_close(self, code=1000, reason=''):
71 return struct.pack('!H', code) + reason.encode('utf-8')
72
56 resp += sock.recv(4096).decode()
57
58 if (
59 re.search('101 Switching Protocols', resp)
60 and resp[-4:] == '\r\n\r\n'
61 ):
62 resp = self._resp_to_dict(resp)
63 break
64
65 return (resp, sock, key)
66
67 def apply_mask(self, data, mask):
68 return bytes(b ^ m for b, m in zip(data, itertools.cycle(mask)))
69
70 def serialize_close(self, code=1000, reason=''):
71 return struct.pack('!H', code) + reason.encode('utf-8')
72
73 def frame_read(self, sock, read_timeout=30):
73 def frame_read(self, sock, read_timeout=60):
74 def recv_bytes(sock, bytes):
75 data = b''
76 while select.select([sock], [], [], read_timeout)[0]:
77 data += sock.recv(bytes - len(data))
78
79 if len(data) == bytes:
80 break
81

--- 151 unchanged lines hidden ---
74 def recv_bytes(sock, bytes):
75 data = b''
76 while select.select([sock], [], [], read_timeout)[0]:
77 data += sock.recv(bytes - len(data))
78
79 if len(data) == bytes:
80 break
81

--- 151 unchanged lines hidden ---