diff options
Diffstat (limited to 'libmproxy')
-rw-r--r-- | libmproxy/protocol/http.py | 17 | ||||
-rw-r--r-- | libmproxy/proxy/connection.py | 2 |
2 files changed, 16 insertions, 3 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 diff --git a/libmproxy/proxy/connection.py b/libmproxy/proxy/connection.py index 38436233..a19e3e71 100644 --- a/libmproxy/proxy/connection.py +++ b/libmproxy/proxy/connection.py @@ -138,7 +138,7 @@ class ServerConnection(tcp.TCPClient, stateobject.SimpleStateObject): self.convert_to_ssl(cert=clientcert, sni=sni) self.timestamp_ssl_setup = utils.timestamp() except tcp.NetLibError, v: - raise ProxyError(400, str(v)) + raise ProxyError(400, repr(v)) def finish(self): tcp.TCPClient.finish(self) |