From 0c3f2a3806f33208aeca79711e8b70e07107e7c1 Mon Sep 17 00:00:00 2001 From: Thomas Kriechbaumer Date: Sat, 13 Aug 2016 16:56:05 +0200 Subject: [PATCH] fix #1430 --- mitmproxy/exceptions.py | 4 ++++ mitmproxy/protocol/http2.py | 24 +++++++++++------------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/mitmproxy/exceptions.py b/mitmproxy/exceptions.py index 6ca11b258..948765146 100644 --- a/mitmproxy/exceptions.py +++ b/mitmproxy/exceptions.py @@ -103,6 +103,10 @@ class ControlException(ProxyException): pass +class SetServerNotAllowedException(ProxyException): + pass + + class OptionsError(Exception): pass diff --git a/mitmproxy/protocol/http2.py b/mitmproxy/protocol/http2.py index 8308f44de..eb5586cb2 100644 --- a/mitmproxy/protocol/http2.py +++ b/mitmproxy/protocol/http2.py @@ -109,15 +109,6 @@ class Http2Layer(base.Layer): self.server_conn.send(self.server_conn.h2.data_to_send()) self.active_conns.append(self.server_conn.connection) - def connect(self): # pragma: no cover - raise exceptions.Http2ProtocolException("HTTP2 layer should already have a connection.") - - def set_server(self): # pragma: no cover - raise exceptions.Http2ProtocolException("Cannot change server for HTTP2 connections.") - - def disconnect(self): # pragma: no cover - raise exceptions.Http2ProtocolException("Cannot dis- or reconnect in HTTP2 connections.") - def next_layer(self): # pragma: no cover # WebSockets over HTTP/2? # CONNECT for proxying? @@ -382,15 +373,20 @@ class Http2SingleStreamLayer(http._HttpTransmissionLayer, basethread.BaseThread) self.priority_weight = None self.handled_priority_event = None + def connect(self): # pragma: no cover + raise exceptions.Http2ProtocolException("HTTP2 layer should already have a connection.") + + def disconnect(self): # pragma: no cover + raise exceptions.Http2ProtocolException("Cannot dis- or reconnect in HTTP2 connections.") + + def set_server(self, address): # pragma: no cover + raise exceptions.SetServerNotAllowedException(repr(address)) + def check_close_connection(self, flow): # This layer only handles a single stream. # RFC 7540 8.1: An HTTP request/response exchange fully consumes a single stream. return True - def set_server(self, *args, **kwargs): # pragma: no cover - # do not mess with the server connection - all streams share it. - pass - @property def data_queue(self): if self.response_arrived.is_set(): @@ -584,6 +580,8 @@ class Http2SingleStreamLayer(http._HttpTransmissionLayer, basethread.BaseThread) except exceptions.ProtocolException as e: # pragma: no cover self.log(repr(e), "info") self.log(traceback.format_exc(), "debug") + except exceptions.SetServerNotAllowedException as e: # pragma: no cover + self.log("Changing the Host server for HTTP/2 connections not allowed: {}".format(e), "info") except exceptions.Kill: self.log("Connection killed", "info")