From e5414ae2d3c124b192fd057ed44441ca5298a87f Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Fri, 26 May 2017 17:59:19 +0200 Subject: http2: prevent KeyError --- mitmproxy/proxy/protocol/http2.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/mitmproxy/proxy/protocol/http2.py b/mitmproxy/proxy/protocol/http2.py index 2191b54b..ace7ecde 100644 --- a/mitmproxy/proxy/protocol/http2.py +++ b/mitmproxy/proxy/protocol/http2.py @@ -206,14 +206,15 @@ class Http2Layer(base.Layer): return True def _handle_stream_reset(self, eid, event, is_server, other_conn): - self.streams[eid].kill() - if eid in self.streams and event.error_code == h2.errors.ErrorCodes.CANCEL: - if is_server: - other_stream_id = self.streams[eid].client_stream_id - else: - other_stream_id = self.streams[eid].server_stream_id - if other_stream_id is not None: - self.connections[other_conn].safe_reset_stream(other_stream_id, event.error_code) + if eid in self.streams: + self.streams[eid].kill() + if event.error_code == h2.errors.ErrorCodes.CANCEL: + if is_server: + other_stream_id = self.streams[eid].client_stream_id + else: + other_stream_id = self.streams[eid].server_stream_id + if other_stream_id is not None: + self.connections[other_conn].safe_reset_stream(other_stream_id, event.error_code) return True def _handle_remote_settings_changed(self, event, other_conn): -- cgit v1.2.3