diff options
| author | Maximilian Hils <git@maximilianhils.com> | 2017-11-06 11:23:16 +0100 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2017-11-06 11:23:16 +0100 | 
| commit | 4cb96dedd0143cf9b6278d3622457e1e485b3090 (patch) | |
| tree | 311b3c5cfecdf3c316ee42db9d0d5a06c7be3073 | |
| parent | 1d55d241f8f3c3c49a67777de42c9636a39c93db (diff) | |
| parent | 7e5eea19298d485584cda23e3e5bf63d473feb17 (diff) | |
| download | mitmproxy-4cb96dedd0143cf9b6278d3622457e1e485b3090.tar.gz mitmproxy-4cb96dedd0143cf9b6278d3622457e1e485b3090.tar.bz2 mitmproxy-4cb96dedd0143cf9b6278d3622457e1e485b3090.zip | |
Merge pull request #2619 from mhils/issue-2617
Fix #2617
| -rw-r--r-- | mitmproxy/proxy/protocol/base.py | 26 | ||||
| -rw-r--r-- | mitmproxy/proxy/protocol/http.py | 8 | 
2 files changed, 16 insertions, 18 deletions
| diff --git a/mitmproxy/proxy/protocol/base.py b/mitmproxy/proxy/protocol/base.py index 7c0f78ae..f1b8da6c 100644 --- a/mitmproxy/proxy/protocol/base.py +++ b/mitmproxy/proxy/protocol/base.py @@ -96,15 +96,7 @@ class ServerConnectionMixin:      def __init__(self, server_address=None):          super().__init__() -        self.server_conn = None -        if self.config.options.spoof_source_address and self.config.options.upstream_bind_address == '': -            self.server_conn = connections.ServerConnection( -                server_address, (self.ctx.client_conn.address[0], 0), True) -        else: -            self.server_conn = connections.ServerConnection( -                server_address, (self.config.options.upstream_bind_address, 0), -                self.config.options.spoof_source_address -            ) +        self.server_conn = self.__make_server_conn(server_address)          self.__check_self_connect() @@ -125,6 +117,16 @@ class ServerConnectionMixin:                      "The proxy shall not connect to itself.".format(repr(address))                  ) +    def __make_server_conn(self, server_address): +        if self.config.options.spoof_source_address and self.config.options.upstream_bind_address == '': +            return connections.ServerConnection( +                server_address, (self.ctx.client_conn.address[0], 0), True) +        else: +            return connections.ServerConnection( +                server_address, (self.config.options.upstream_bind_address, 0), +                self.config.options.spoof_source_address +            ) +      def set_server(self, address):          """          Sets a new server address. If there is an existing connection, it will be closed. @@ -146,11 +148,7 @@ class ServerConnectionMixin:          self.server_conn.close()          self.channel.tell("serverdisconnect", self.server_conn) -        self.server_conn = connections.ServerConnection( -            address, -            (self.server_conn.source_address[0], 0), -            self.config.options.spoof_source_address -        ) +        self.server_conn = self.__make_server_conn(address)      def connect(self):          """ diff --git a/mitmproxy/proxy/protocol/http.py b/mitmproxy/proxy/protocol/http.py index a366861d..57ac0f16 100644 --- a/mitmproxy/proxy/protocol/http.py +++ b/mitmproxy/proxy/protocol/http.py @@ -165,7 +165,7 @@ class HttpLayer(base.Layer):      def __init__(self, ctx, mode):          super().__init__(ctx)          self.mode = mode -        self.__initial_server_conn = None +        self.__initial_server_address = None  # type: tuple          "Contains the original destination in transparent mode, which needs to be restored"          "if an inline script modified the target server for a single http request"          # We cannot rely on server_conn.tls_established, @@ -177,7 +177,7 @@ class HttpLayer(base.Layer):      def __call__(self):          if self.mode == HTTPMode.transparent:              self.__initial_server_tls = self.server_tls -            self.__initial_server_conn = self.server_conn +            self.__initial_server_address = self.server_conn.address          while True:              flow = http.HTTPFlow(                  self.client_conn, @@ -313,8 +313,8 @@ class HttpLayer(base.Layer):              # Setting request.host also updates the host header, which we want              # to preserve              host_header = f.request.host_header -            f.request.host = self.__initial_server_conn.address[0] -            f.request.port = self.__initial_server_conn.address[1] +            f.request.host = self.__initial_server_address[0] +            f.request.port = self.__initial_server_address[1]              f.request.host_header = host_header  # set again as .host overwrites this.              f.request.scheme = "https" if self.__initial_server_tls else "http"          self.channel.ask("request", f) | 
