From 1004460ba670c503702a46c01518c1da19c5047c Mon Sep 17 00:00:00 2001 From: Biping Meng Date: Wed, 26 Jul 2017 18:19:38 +0800 Subject: [PATCH] Allow http_connect to create a response for CONNECT request so that connection to server be postponed in upstream mode. --- mitmproxy/proxy/protocol/http.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/mitmproxy/proxy/protocol/http.py b/mitmproxy/proxy/protocol/http.py index 502280c14..728c2ba10 100644 --- a/mitmproxy/proxy/protocol/http.py +++ b/mitmproxy/proxy/protocol/http.py @@ -217,16 +217,17 @@ class HttpLayer(base.Layer): return False def handle_upstream_connect(self, f): - self.establish_server_connection( - f.request.host, - f.request.port, - f.request.scheme - ) - self.send_request(f.request) - f.response = self.read_response_headers() - f.response.data.content = b"".join( - self.read_response_body(f.request, f.response) - ) + if not f.response: + self.establish_server_connection( + f.request.host, + f.request.port, + f.request.scheme + ) + self.send_request(f.request) + f.response = self.read_response_headers() + f.response.data.content = b"".join( + self.read_response_body(f.request, f.response) + ) self.send_response(f.response) if is_ok(f.response.status_code): layer = UpstreamConnectLayer(self, f.request)