http2: use callback for handle unexpected frames

This commit is contained in:
Thomas Kriechbaumer 2015-08-19 21:09:48 +02:00
parent 721bd1c136
commit 4339b8e7fa

View File

@ -68,8 +68,8 @@ class Http2Layer(Layer):
def __init__(self, ctx, mode): def __init__(self, ctx, mode):
super(Http2Layer, self).__init__(ctx) super(Http2Layer, self).__init__(ctx)
self.mode = mode self.mode = mode
self.client_protocol = HTTP2Protocol(self.client_conn, is_server=True) self.client_protocol = HTTP2Protocol(self.client_conn, is_server=True, unhandled_frame_cb=self.handle_unexpected_frame)
self.server_protocol = HTTP2Protocol(self.server_conn, is_server=False) self.server_protocol = HTTP2Protocol(self.server_conn, is_server=False, unhandled_frame_cb=self.handle_unexpected_frame)
def read_from_client(self): def read_from_client(self):
return HTTPRequest.from_protocol( return HTTPRequest.from_protocol(
@ -95,17 +95,17 @@ class Http2Layer(Layer):
def connect(self): def connect(self):
self.ctx.connect() self.ctx.connect()
self.server_protocol = HTTP2Protocol(self.server_conn, is_server=False) self.server_protocol = HTTP2Protocol(self.server_conn, is_server=False, unhandled_frame_cb=self.handle_unexpected_frame)
self.server_protocol.perform_connection_preface() self.server_protocol.perform_connection_preface()
def reconnect(self): def reconnect(self):
self.ctx.reconnect() self.ctx.reconnect()
self.server_protocol = HTTP2Protocol(self.server_conn, is_server=False) self.server_protocol = HTTP2Protocol(self.server_conn, is_server=False, unhandled_frame_cb=self.handle_unexpected_frame)
self.server_protocol.perform_connection_preface() self.server_protocol.perform_connection_preface()
def set_server(self, *args, **kwargs): def set_server(self, *args, **kwargs):
self.ctx.set_server(*args, **kwargs) self.ctx.set_server(*args, **kwargs)
self.server_protocol = HTTP2Protocol(self.server_conn, is_server=False) self.server_protocol = HTTP2Protocol(self.server_conn, is_server=False, unhandled_frame_cb=self.handle_unexpected_frame)
self.server_protocol.perform_connection_preface() self.server_protocol.perform_connection_preface()
def __call__(self): def __call__(self):
@ -113,6 +113,9 @@ class Http2Layer(Layer):
layer = HttpLayer(self, self.mode) layer = HttpLayer(self, self.mode)
layer() layer()
def handle_unexpected_frame(self, frm):
print(frm.human_readable())
def make_error_response(status_code, message, headers=None): def make_error_response(status_code, message, headers=None):
response = status_codes.RESPONSES.get(status_code, "Unknown") response = status_codes.RESPONSES.get(status_code, "Unknown")