def socket_handler(listener): sock = listener.accept()[0] # Dispose of the first two packets. sock.recv(65535) sock.recv(65535) # Send a Settings frame that reduces the flow-control window to # 64 bytes. f = SettingsFrame(0) f.settings[SettingsFrame.INITIAL_WINDOW_SIZE] = 64 sock.send(f.serialize()) # Grab three frames, the settings ACK, the initial headers frame, # and the first data frame. for x in range(0, 3): data.append(sock.recv(65535)) # Send a WindowUpdate giving more window room to the stream. f = WindowUpdateFrame(1) f.window_increment = 64 sock.send(f.serialize()) # Reeive the remaining frame. data.append(sock.recv(65535)) send_event.set() # We're done. sock.close()
def socket_handler(listener): sock = listener.accept()[0] # Dispose of the first two packets. sock.recv(65535) sock.recv(65535) # Send a Settings frame that reduces the flow-control window to # 64 bytes. f = SettingsFrame(0) f.settings[SettingsFrame.INITIAL_WINDOW_SIZE] = 64 sock.send(f.serialize()) # Grab three frames, the settings ACK, the initial headers frame, # and the first data frame. for x in range(0, 3): data.append(sock.recv(65535)) # Send a WindowUpdate giving more window room to the stream. f = WindowUpdateFrame(1) f.window_increment = 64 sock.send(f.serialize()) # Send one that gives more room to the connection. f = WindowUpdateFrame(0) f.window_increment = 64 sock.send(f.serialize()) # Reeive the remaining frame. data.append(sock.recv(65535)) send_event.set() # We're done. sock.close()
def socket_handler(listener): sock = listener.accept()[0] # We should get two packets: one connection header string, one # SettingsFrame. first = sock.recv(65535) second = sock.recv(65535) data.append(first) data.append(second) # We need to send back a SettingsFrame. f = SettingsFrame(0) sock.send(f.serialize()) send_event.set() sock.close()
def receive_preamble(sock): # Receive the HTTP/2.0 'preamble'. sock.recv(65535) sock.recv(65535) sock.send(SettingsFrame(0).serialize()) sock.recv(65535) return
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 test_settings_frame_serializes_properly(self): f = SettingsFrame(0) f.parse_flags(0xFF) f.settings = { SettingsFrame.HEADER_TABLE_SIZE: 4096, SettingsFrame.ENABLE_PUSH: 0, SettingsFrame.MAX_CONCURRENT_STREAMS: 100, SettingsFrame.INITIAL_WINDOW_SIZE: 65535, SettingsFrame.FLOW_CONTROL_OPTIONS: 1, } s = f.serialize() assert s == ( b'\x00\x28\x04\x01\x00\x00\x00\x00' + # Frame header b'\x00\x00\x00\x01\x00\x00\x10\x00' + # HEADER_TABLE_SIZE b'\x00\x00\x00\x02\x00\x00\x00\x00' + # ENABLE_PUSH b'\x00\x00\x00\x04\x00\x00\x00\x64' + # MAX_CONCURRENT_STREAMS b'\x00\x00\x00\x0A\x00\x00\x00\x01' + # FLOW_CONTROL_OPTIONS b'\x00\x00\x00\x07\x00\x00\xFF\xFF' # INITIAL_WINDOW_SIZE )
def test_connections_handle_resizing_header_tables_properly(self): sock = DummySocket() f = SettingsFrame(0) f.settings[SettingsFrame.HEADER_TABLE_SIZE] = 1024 c = HTTP20Connection('www.google.com') c._sock = sock # 'Receive' the SETTINGS frame. c.receive_frame(f) # Confirm that the setting is stored and the header table shrunk. assert c._settings[SettingsFrame.HEADER_TABLE_SIZE] == 1024 assert c.encoder.header_table_size == 1024 # Confirm we got a SETTINGS ACK. f2 = decode_frame(sock.queue[0]) assert isinstance(f2, SettingsFrame) assert f2.stream_id == 0 assert f2.flags == set(['ACK'])
def test_settings_frame_has_only_one_flag(self): f = SettingsFrame(0) flags = f.parse_flags(0xFF) assert flags == set(['ACK'])
def test_settings_frames_never_have_streams(self): with pytest.raises(ValueError): SettingsFrame(1)