diff --git a/mitmproxy/proxy/protocol/http2.py b/mitmproxy/proxy/protocol/http2.py index f635e7108..b1154fae3 100644 --- a/mitmproxy/proxy/protocol/http2.py +++ b/mitmproxy/proxy/protocol/http2.py @@ -25,17 +25,13 @@ class SafeH2Connection(connection.H2Connection): self.conn = conn self.lock = threading.RLock() - def safe_increment_flow_control(self, stream_id, length): - if length == 0: + def safe_acknowledge_received_data(self, acknowledged_size, stream_id): + if acknowledged_size == 0: return with self.lock: - self.increment_flow_control_window(length) + self.acknowledge_received_data(acknowledged_size, stream_id) self.conn.send(self.data_to_send()) - with self.lock: - if stream_id in self.streams and not self.streams[stream_id].closed: - self.increment_flow_control_window(length, stream_id=stream_id) - self.conn.send(self.data_to_send()) def safe_reset_stream(self, stream_id, error_code): with self.lock: @@ -90,13 +86,25 @@ class Http2Layer(base.Layer): self.mode = mode self.streams = dict() self.server_to_client_stream_ids = dict([(0, 0)]) - self.client_conn.h2 = SafeH2Connection(self.client_conn, client_side=False, header_encoding=False) + config = h2.config.H2Configuration( + client_side=False, + header_encoding=False, + validate_outbound_headers=False, + normalize_outbound_headers=False, + validate_inbound_headers=False) + self.client_conn.h2 = SafeH2Connection(self.client_conn, config=config) def _initiate_server_conn(self): if self.server_conn: - self.server_conn.h2 = SafeH2Connection(self.server_conn, client_side=True, header_encoding=False) - self.server_conn.h2.initiate_connection() - self.server_conn.send(self.server_conn.h2.data_to_send()) + config = h2.config.H2Configuration( + client_side=True, + header_encoding=False, + validate_outbound_headers=False, + normalize_outbound_headers=False, + validate_inbound_headers=False) + self.server_conn.h2 = SafeH2Connection(self.server_conn, config=config) + self.server_conn.h2.initiate_connection() + self.server_conn.send(self.server_conn.h2.data_to_send()) def _complete_handshake(self): preamble = self.client_conn.rfile.read(24) @@ -181,9 +189,9 @@ class Http2Layer(base.Layer): else: self.streams[eid].data_queue.put(event.data) self.streams[eid].queued_data_length += len(event.data) - source_conn.h2.safe_increment_flow_control( - event.stream_id, - event.flow_controlled_length + source_conn.h2.safe_acknowledge_received_data( + event.flow_controlled_length, + event.stream_id ) return True diff --git a/setup.py b/setup.py index fc773404f..70ff8b5d7 100644 --- a/setup.py +++ b/setup.py @@ -67,7 +67,7 @@ setup( "cryptography>=1.3, <1.6", "cssutils>=1.0.1, <1.1", "Flask>=0.10.1, <0.12", - "h2>=2.4.1, <3", + "h2>=2.5.0, <3", "html2text>=2016.1.8, <=2016.9.19", "hyperframe>=4.0.1, <5", "jsbeautifier>=1.6.3, <1.7", diff --git a/test/mitmproxy/protocol/test_http2.py b/test/mitmproxy/protocol/test_http2.py index 4629d1099..a2eeea522 100644 --- a/test/mitmproxy/protocol/test_http2.py +++ b/test/mitmproxy/protocol/test_http2.py @@ -298,9 +298,9 @@ class TestRequestWithPriority(_Http2Test): headers = [(':status', '200')] if event.priority_updated: - headers.append(('priority_exclusive', event.priority_updated.exclusive)) - headers.append(('priority_depends_on', event.priority_updated.depends_on)) - headers.append(('priority_weight', event.priority_updated.weight)) + headers.append(('priority_exclusive', str(event.priority_updated.exclusive).encode())) + headers.append(('priority_depends_on', str(event.priority_updated.depends_on).encode())) + headers.append(('priority_weight', str(event.priority_updated.weight).encode())) h2_conn.send_headers(event.stream_id, headers) h2_conn.end_stream(event.stream_id) wfile.write(h2_conn.data_to_send())