aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Kriechbaumer <thomas@kriechbaumer.name>2015-08-18 09:49:56 +0200
committerThomas Kriechbaumer <thomas@kriechbaumer.name>2015-08-18 21:22:42 +0200
commit07a1356e2f155d5b9e3a5f97bf90515ed9f1011f (patch)
treefa7e0db07d3b14c4ffe6b567f4fa10a112e1e652
parent0d384ac2a91898d4c8623290ae0fb3a60a35e514 (diff)
downloadmitmproxy-07a1356e2f155d5b9e3a5f97bf90515ed9f1011f.tar.gz
mitmproxy-07a1356e2f155d5b9e3a5f97bf90515ed9f1011f.tar.bz2
mitmproxy-07a1356e2f155d5b9e3a5f97bf90515ed9f1011f.zip
http2: add support for too large header frames
-rw-r--r--netlib/http/http2/protocol.py29
-rw-r--r--test/http/http2/test_protocol.py16
2 files changed, 34 insertions, 11 deletions
diff --git a/netlib/http/http2/protocol.py b/netlib/http/http2/protocol.py
index cc8daba8..c27b4e9e 100644
--- a/netlib/http/http2/protocol.py
+++ b/netlib/http/http2/protocol.py
@@ -274,24 +274,33 @@ class HTTP2Protocol(semantics.ProtocolMixin):
# to be more strict use: self._read_settings_ack(hide)
def _create_headers(self, headers, stream_id, end_stream=True):
- # TODO: implement max frame size checks and sending in chunks
-
- flags = frame.Frame.FLAG_END_HEADERS
- if end_stream:
- flags |= frame.Frame.FLAG_END_STREAM
+ def frame_cls(chunks):
+ for i in chunks:
+ if i == 0:
+ yield frame.HeadersFrame, i
+ else:
+ yield frame.ContinuationFrame, i
header_block_fragment = self.encoder.encode(headers)
- frm = frame.HeadersFrame(
+ chunk_size = self.http2_settings[frame.SettingsFrame.SETTINGS.SETTINGS_MAX_FRAME_SIZE]
+ chunks = range(0, len(header_block_fragment), chunk_size)
+ frms = [frm_cls(
state=self,
- flags=flags,
+ flags=frame.Frame.FLAG_NO_FLAGS,
stream_id=stream_id,
- header_block_fragment=header_block_fragment)
+ header_block_fragment=header_block_fragment[i:i+chunk_size]) for frm_cls, i in frame_cls(chunks)]
+
+ last_flags = frame.Frame.FLAG_END_HEADERS
+ if end_stream:
+ last_flags |= frame.Frame.FLAG_END_STREAM
+ frms[-1].flags = last_flags
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 _create_body(self, body, stream_id):
if body is None or len(body) == 0:
diff --git a/test/http/http2/test_protocol.py b/test/http/http2/test_protocol.py
index 7f3fd2bd..8c38bebd 100644
--- a/test/http/http2/test_protocol.py
+++ b/test/http/http2/test_protocol.py
@@ -247,7 +247,21 @@ class TestCreateHeaders():
'000014010400000001824488355217caf3a69a3f87408294e7838c767f'\
.decode('hex')
- # TODO: add test for too large header_block_fragments
+ def test_create_headers_multiple_frames(self):
+ headers = [
+ (b':method', b'GET'),
+ (b':path', b'/'),
+ (b':scheme', b'https'),
+ (b'foo', b'bar'),
+ (b'server', b'version')]
+
+ protocol = HTTP2Protocol(self.c)
+ protocol.http2_settings[SettingsFrame.SETTINGS.SETTINGS_MAX_FRAME_SIZE] = 8
+ bytes = protocol._create_headers(headers, 1, end_stream=True)
+ assert len(bytes) == 3
+ assert bytes[0] == '000008010000000001828487408294e783'.decode('hex')
+ assert bytes[1] == '0000080900000000018c767f7685ee5b10'.decode('hex')
+ assert bytes[2] == '00000209050000000163d5'.decode('hex')
class TestCreateBody():