aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/protocol/http.py
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2014-08-08 17:49:02 +0200
committerMaximilian Hils <git@maximilianhils.com>2014-08-08 17:49:02 +0200
commit4d2109ef92d59e48c08279e3b59b7cc8385e02df (patch)
tree073435551d0340f85e19384056b5f5acd2909146 /libmproxy/protocol/http.py
parentde05484d9d08a4bc40c17c673b18bc2e0f910fff (diff)
downloadmitmproxy-4d2109ef92d59e48c08279e3b59b7cc8385e02df.tar.gz
mitmproxy-4d2109ef92d59e48c08279e3b59b7cc8385e02df.tar.bz2
mitmproxy-4d2109ef92d59e48c08279e3b59b7cc8385e02df.zip
fix display of urls in upstream mode, refs #308
Diffstat (limited to 'libmproxy/protocol/http.py')
-rw-r--r--libmproxy/protocol/http.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py
index e4f994c9..7c4d9cbb 100644
--- a/libmproxy/protocol/http.py
+++ b/libmproxy/protocol/http.py
@@ -461,7 +461,12 @@ class HTTPRequest(HTTPMessage):
if self.host:
host = self.host
else:
- host = self.flow.server_conn.address.host
+ for s in self.flow.server_conn.state:
+ if s[0] == "http" and s[1].get("state") == "connect":
+ host = s[1]["host"]
+ break
+ if not host:
+ host = self.flow.server_conn.address.host
host = host.encode("idna")
return host
@@ -479,6 +484,9 @@ class HTTPRequest(HTTPMessage):
"""
if self.port:
return self.port
+ for s in self.flow.server_conn.state:
+ if s[0] == "http" and s[1].get("state") == "connect":
+ return s[1]["port"]
return self.flow.server_conn.address.port
def get_url(self, hostheader=False):
@@ -974,11 +982,16 @@ class HTTPHandler(ProtocolHandler, TemporaryServerChangeMixin):
return False
if flow.request.form_in == "authority" and flow.response.code == 200:
- self.ssl_upgrade()
# TODO: Eventually add headers (space/usefulness tradeoff)
+ # Make sure to add state info before the actual upgrade happens.
+ # During the upgrade, we may receive an SNI indication from the client,
+ # which resets the upstream connection. If this is the case, we must
+ # already re-issue the CONNECT request at this point.
self.c.server_conn.state.append(("http", {"state": "connect",
"host": flow.request.host,
"port": flow.request.port}))
+ self.ssl_upgrade()
+
# If the user has changed the target server on this connection,
# restore the original target server