From bee12019183c461497e8e8f05ccfd9460353a0cb Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Mon, 8 Feb 2016 19:41:11 +0100 Subject: [PATCH] fix #920 This might be implemented by hyper-h2 in the future. --- libmproxy/protocol/http2.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/libmproxy/protocol/http2.py b/libmproxy/protocol/http2.py index 8ccc209a7..7bf06d31a 100644 --- a/libmproxy/protocol/http2.py +++ b/libmproxy/protocol/http2.py @@ -9,6 +9,7 @@ from netlib.exceptions import HttpException from netlib.http import Headers from netlib.utils import http2_read_raw_frame +import hyperframe import h2 from h2.connection import H2Connection from h2.events import * @@ -97,6 +98,8 @@ class Http2Layer(Layer): super(Http2Layer, self).__init__(ctx) self.mode = mode self.streams = dict() + self.client_reset_streams = [] + self.server_reset_streams = [] self.server_to_client_stream_ids = dict([(0, 0)]) self.client_conn.h2 = SafeH2Connection(self.client_conn, client_side=False) @@ -156,6 +159,8 @@ class Http2Layer(Layer): self.streams[eid].data_finished.set() elif isinstance(event, StreamReset): self.streams[eid].zombie = time.time() + self.client_reset_streams.append(self.streams[eid].client_stream_id) + self.server_reset_streams.append(self.streams[eid].server_stream_id) if self.streams[eid].server_stream_id if eid in self.streams and event.error_code == 0x8: if is_server: other_stream_id = self.streams[eid].client_stream_id @@ -222,6 +227,20 @@ class Http2Layer(Layer): stream.zombie = time.time() return + + frame, _ = hyperframe.frame.Frame.parse_frame_header(raw_frame[:9]) + + if is_server: + list = self.server_reset_streams + else: + list = self.client_reset_streams + if frame.stream_id in list: + # this frame belongs to a reset stream - just ignore it + if isinstance(frame, hyperframe.frame.HeadersFrame) or isinstance(frame, hyperframe.frame.ContinuationFrame): + # we need to keep the hpack-decoder happy too + source_conn.h2.decoder.decode(raw_frame[9:]) + continue + events = source_conn.h2.receive_data(raw_frame) source_conn.send(source_conn.h2.data_to_send())