This might be implemented by hyper-h2 in the future.
This commit is contained in:
Thomas Kriechbaumer 2016-02-08 19:41:11 +01:00
parent ec087a1960
commit bee1201918

View File

@ -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())