From afff1f17340b2a62de168ec42655ed7e5779c3c4 Mon Sep 17 00:00:00 2001 From: Matthias Urlichs Date: Thu, 12 Dec 2013 10:00:23 +0100 Subject: [PATCH] Reconnect if the server-connect hook needs the request to decide what to do --- libmproxy/proxy.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index 38356a93f..77c8828a5 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -141,14 +141,17 @@ class ProxyHandler(tcp.BaseHandler): breaks, we'll have to do something different with the SNI host variable on the handler object. - `conn_info` holds the initial connection's parameters. - The hook might change them. + `conn_info` holds the initial connection's parameters, as the + hook might change them. Also, the hook might require an initial + request to figure out connection settings; in this case it can + set require_request, which will cause the connection to be + re-opened after the client's request arrives. """ sc = self.server_conn if not sni: sni = host conn_info = (scheme, host, port, sni) - if sc and conn_info != sc.conn_info: + if sc and (conn_info != sc.conn_info or request and sc.require_request): sc.terminate() self.server_conn = None self.log( @@ -163,7 +166,12 @@ class ProxyHandler(tcp.BaseHandler): if not self.server_conn: try: self.server_conn = ServerConnection(self.config, scheme, host, port, sni) - self.server_conn.request = request # the hook might need it + + # Additional attributes, used if the server_connect hook + # needs to change parameters + self.server_conn.request = request + self.server_conn.require_request = False + self.server_conn.conn_info = conn_info self.channel.ask(self.server_conn) self.server_conn.connect()