def test_headers_frame_serialize_without_priority_properly(self): f = HeadersFrame(1) f.parse_flags(0xFF) f.data = b'hello world' s = f.serialize() assert s == (b'\x00\x0B\x01\x0D\x00\x00\x00\x01' + b'hello world')
def socket_handler(listener): sock = listener.accept()[0] # Do the handshake: conn header, settings, send settings, recv ack. receive_preamble(sock) # Now expect some data. One headers frame and one data frame. data.append(sock.recv(65535)) data.append(sock.recv(65535)) # Respond! h = HeadersFrame(1) h.data = self.get_encoder().encode({ ':status': 200, 'Content-Type': 'not/real', 'Content-Length': 20 }) h.flags.add('END_HEADERS') sock.send(h.serialize()) d = DataFrame(1) d.data = b'1234567890' * 2 d.flags.add('END_STREAM') sock.send(d.serialize()) send_event.set() sock.close()
def build_headers_frame(headers): f = HeadersFrame(1) e = Encoder() e.huffman_coder = HuffmanEncoder(RESPONSE_CODES, RESPONSE_CODES_LENGTH) f.data = e.encode(headers) f.flags.add('END_HEADERS') return f
def test_headers_frame_serialize_without_priority_properly(self): f = HeadersFrame(1) f.parse_flags(0xFF) f.data = b"hello world" s = f.serialize() assert s == (b"\x00\x0B\x01\x0D\x00\x00\x00\x01" + b"hello world")
def socket_handler(listener): sock = listener.accept()[0] # Do the handshake: conn header, settings, send settings, recv ack. sock.recv(65535) sock.recv(65535) sock.send(SettingsFrame(0).serialize()) sock.recv(65535) # Now expect some data. One headers frame and one data frame. data.append(sock.recv(65535)) data.append(sock.recv(65535)) # Respond! h = HeadersFrame(1) h.data = self.get_encoder().encode({':status': 200, 'Content-Type': 'not/real', 'Content-Length': 20}) h.flags.add('END_HEADERS') sock.send(h.serialize()) d = DataFrame(1) d.data = b'1234567890' * 2 d.flags.add('END_STREAM') sock.send(d.serialize()) send_event.set() sock.close()
def build_headers_frame(headers, encoder=None): f = HeadersFrame(1) e = encoder if e is None: e = Encoder() e.huffman_coder = HuffmanEncoder(REQUEST_CODES, REQUEST_CODES_LENGTH) f.data = e.encode(headers) f.flags.add('END_HEADERS') return f
def test_headers_frame_serialize_with_priority_properly(self): f = HeadersFrame(1) f.parse_flags(0xFF) f.priority = (2 ** 30) + 1 f.data = b'hello world' s = f.serialize() assert s == ( b'\x00\x0F\x01\x0D\x00\x00\x00\x01' + b'\x40\x00\x00\x01' + b'hello world' )