From 0d384ac2a91898d4c8623290ae0fb3a60a35e514 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Mon, 17 Aug 2015 22:55:33 +0200 Subject: http2: add support for too large data frames --- netlib/http/http2/protocol.py | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'netlib/http/http2/protocol.py') diff --git a/netlib/http/http2/protocol.py b/netlib/http/http2/protocol.py index c2ad5edd..cc8daba8 100644 --- a/netlib/http/http2/protocol.py +++ b/netlib/http/http2/protocol.py @@ -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 - # TODO: implement flow-control window - - frm = frame.DataFrame( + 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_END_STREAM, + flags=frame.Frame.FLAG_NO_FLAGS, stream_id=stream_id, - payload=body) + payload=body[i:i+chunk_size]) for i in chunks] + frms[-1].flags = frame.Frame.FLAG_END_STREAM + + # TODO: implement flow-control window 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 -- cgit v1.2.3 From 07a1356e2f155d5b9e3a5f97bf90515ed9f1011f Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Tue, 18 Aug 2015 09:49:56 +0200 Subject: http2: add support for too large header frames --- netlib/http/http2/protocol.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'netlib/http/http2/protocol.py') 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: -- cgit v1.2.3 From 9686a77dcb640ace74f923c1f0f7f7307f79edfe Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Sun, 16 Aug 2015 20:02:18 +0200 Subject: http2: implement request target --- netlib/http/http2/protocol.py | 39 +++++++++++++++++++++++++++++++++------ 1 file changed, 33 insertions(+), 6 deletions(-) (limited to 'netlib/http/http2/protocol.py') diff --git a/netlib/http/http2/protocol.py b/netlib/http/http2/protocol.py index c27b4e9e..eacbd2d8 100644 --- a/netlib/http/http2/protocol.py +++ b/netlib/http/http2/protocol.py @@ -80,13 +80,39 @@ class HTTP2Protocol(semantics.ProtocolMixin): timestamp_end = time.time() + authority = headers.get_first(':authority', '') + method = headers.get_first(':method', 'GET') + scheme = headers.get_first(':scheme', 'https') + path = headers.get_first(':path', '/') + host = None + port = None + + if path == '*' or path.startswith("/"): + form_in = "relative" + elif method == 'CONNECT': + form_in = "authority" + if ":" in authority: + host, port = authority.split(":", 1) + else: + host = authority + else: + form_in = "absolute" + # FIXME: verify if path or :host contains what we need + scheme, host, port, _ = utils.parse_url(path) + + if host is None: + host = 'localhost' + if port is None: + port = 80 if scheme == 'http' else 443 + port = int(port) + request = http.Request( - "relative", # TODO: use the correct value - headers.get_first(':method', 'GET'), - headers.get_first(':scheme', 'https'), - headers.get_first(':host', 'localhost'), - 443, # TODO: parse port number from host? - headers.get_first(':path', '/'), + form_in, + method, + scheme, + host, + port, + path, (2, 0), headers, body, @@ -324,6 +350,7 @@ class HTTP2Protocol(semantics.ProtocolMixin): return [frm.to_bytes() for frm in frms] def _receive_transmission(self, include_body=True): + # TODO: include_body is not respected body_expected = True stream_id = 0 -- cgit v1.2.3