http2: add support for too large data frames

This commit is contained in:
Thomas Kriechbaumer 2015-08-17 22:55:33 +02:00
parent 12efa61e3a
commit 0d384ac2a9
2 changed files with 23 additions and 15 deletions

View File

@ -297,19 +297,22 @@ class HTTP2Protocol(semantics.ProtocolMixin):
if body is None or len(body) == 0:
return b''
# TODO: implement max frame size checks and sending in chunks
chunk_size = self.http2_settings[frame.SettingsFrame.SETTINGS.SETTINGS_MAX_FRAME_SIZE]
chunks = range(0, len(body), chunk_size)
frms = [frame.DataFrame(
state=self,
flags=frame.Frame.FLAG_NO_FLAGS,
stream_id=stream_id,
payload=body[i:i+chunk_size]) for i in chunks]
frms[-1].flags = frame.Frame.FLAG_END_STREAM
# TODO: implement flow-control window
frm = frame.DataFrame(
state=self,
flags=frame.Frame.FLAG_END_STREAM,
stream_id=stream_id,
payload=body)
if self.dump_frames: # pragma no cover
print(frm.human_readable(">>"))
for frm in frms:
print(frm.human_readable(">>"))
return [frm.to_bytes()]
return [frm.to_bytes() for frm in frms]
def _receive_transmission(self, include_body=True):
body_expected = True

View File

@ -252,20 +252,25 @@ class TestCreateHeaders():
class TestCreateBody():
c = tcp.TCPClient(("127.0.0.1", 0))
protocol = HTTP2Protocol(c)
def test_create_body_empty(self):
bytes = self.protocol._create_body(b'', 1)
protocol = HTTP2Protocol(self.c)
bytes = protocol._create_body(b'', 1)
assert b''.join(bytes) == ''.decode('hex')
def test_create_body_single_frame(self):
bytes = self.protocol._create_body('foobar', 1)
protocol = HTTP2Protocol(self.c)
bytes = protocol._create_body('foobar', 1)
assert b''.join(bytes) == '000006000100000001666f6f626172'.decode('hex')
def test_create_body_multiple_frames(self):
pass
# bytes = self.protocol._create_body('foobar' * 3000, 1)
# TODO: add test for too large frames
protocol = HTTP2Protocol(self.c)
protocol.http2_settings[SettingsFrame.SETTINGS.SETTINGS_MAX_FRAME_SIZE] = 5
bytes = protocol._create_body('foobarmehm42', 1)
assert len(bytes) == 3
assert bytes[0] == '000005000000000001666f6f6261'.decode('hex')
assert bytes[1] == '000005000000000001726d65686d'.decode('hex')
assert bytes[2] == '0000020001000000013432'.decode('hex')
class TestReadRequest(tservers.ServerTestBase):