diff options
| author | Maximilian Hils <git@maximilianhils.com> | 2017-07-26 12:57:21 +0200 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-07-26 12:57:21 +0200 | 
| commit | 874d0aa25367274c46f6b8ba2a91def66503407e (patch) | |
| tree | 215b27164235418a34280ff12ec162b76df51801 | |
| parent | d409a6c09a873c8131c5e6938aea496904f324c3 (diff) | |
| parent | 6fcd1895bb366c8c14eee28c5bdb097680fcfb15 (diff) | |
| download | mitmproxy-874d0aa25367274c46f6b8ba2a91def66503407e.tar.gz mitmproxy-874d0aa25367274c46f6b8ba2a91def66503407e.tar.bz2 mitmproxy-874d0aa25367274c46f6b8ba2a91def66503407e.zip | |
Merge pull request #2473 from mengbiping/postpone-connection
Respect response to CONNECT created in http_connect function in upstream mode
| -rw-r--r-- | mitmproxy/proxy/protocol/http.py | 23 | 
1 files changed, 13 insertions, 10 deletions
| diff --git a/mitmproxy/proxy/protocol/http.py b/mitmproxy/proxy/protocol/http.py index 502280c1..a366861d 100644 --- a/mitmproxy/proxy/protocol/http.py +++ b/mitmproxy/proxy/protocol/http.py @@ -217,16 +217,19 @@ 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 the user specifies a response in the http_connect hook, we do not connect upstream here. +        # https://github.com/mitmproxy/mitmproxy/pull/2473 +        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) | 
