From 4339b8e7fa1140b9138a023e7e61d78cefe6bb02 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Wed, 19 Aug 2015 21:09:48 +0200 Subject: [PATCH] http2: use callback for handle unexpected frames --- libmproxy/protocol2/http.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libmproxy/protocol2/http.py b/libmproxy/protocol2/http.py index 5170660f8..e227f0ba4 100644 --- a/libmproxy/protocol2/http.py +++ b/libmproxy/protocol2/http.py @@ -68,8 +68,8 @@ class Http2Layer(Layer): def __init__(self, ctx, mode): super(Http2Layer, self).__init__(ctx) self.mode = mode - self.client_protocol = HTTP2Protocol(self.client_conn, is_server=True) - self.server_protocol = HTTP2Protocol(self.server_conn, is_server=False) + 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, unhandled_frame_cb=self.handle_unexpected_frame) def read_from_client(self): return HTTPRequest.from_protocol( @@ -95,17 +95,17 @@ class Http2Layer(Layer): def connect(self): 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() def reconnect(self): 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() def set_server(self, *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() def __call__(self): @@ -113,6 +113,9 @@ class Http2Layer(Layer): layer = HttpLayer(self, self.mode) layer() + def handle_unexpected_frame(self, frm): + print(frm.human_readable()) + def make_error_response(status_code, message, headers=None): response = status_codes.RESPONSES.get(status_code, "Unknown")