aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/proxy
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2014-09-03 20:12:30 +0200
committerMaximilian Hils <git@maximilianhils.com>2014-09-03 20:12:30 +0200
commitcd43c5ba9c2981aeffee354cbcb574b6f5e435ba (patch)
tree025f4a55f2db9a1d9d418e338a638340de0ead4a /libmproxy/proxy
parentb0cfeff06d9dd99a16dfae19c5df3c73c5864fb9 (diff)
downloadmitmproxy-cd43c5ba9c2981aeffee354cbcb574b6f5e435ba.tar.gz
mitmproxy-cd43c5ba9c2981aeffee354cbcb574b6f5e435ba.tar.bz2
mitmproxy-cd43c5ba9c2981aeffee354cbcb574b6f5e435ba.zip
simplify server changes for inline scripts
Diffstat (limited to 'libmproxy/proxy')
-rw-r--r--libmproxy/proxy/connection.py5
-rw-r--r--libmproxy/proxy/primitives.py13
-rw-r--r--libmproxy/proxy/server.py24
3 files changed, 11 insertions, 31 deletions
diff --git a/libmproxy/proxy/connection.py b/libmproxy/proxy/connection.py
index d99ffa9b..5c421557 100644
--- a/libmproxy/proxy/connection.py
+++ b/libmproxy/proxy/connection.py
@@ -72,9 +72,8 @@ class ClientConnection(tcp.BaseHandler, stateobject.SimpleStateObject):
class ServerConnection(tcp.TCPClient, stateobject.SimpleStateObject):
- def __init__(self, address, priority):
+ def __init__(self, address):
tcp.TCPClient.__init__(self, address)
- self.priority = priority
self.state = [] # a list containing (conntype, state) tuples
self.peername = None
@@ -131,7 +130,7 @@ class ServerConnection(tcp.TCPClient, stateobject.SimpleStateObject):
@classmethod
def _from_state(cls, state):
- f = cls(tuple(), None)
+ f = cls(tuple())
f._load_state(state)
return f
diff --git a/libmproxy/proxy/primitives.py b/libmproxy/proxy/primitives.py
index e09f23e4..8c674381 100644
--- a/libmproxy/proxy/primitives.py
+++ b/libmproxy/proxy/primitives.py
@@ -45,19 +45,6 @@ class TransparentUpstreamServerResolver(UpstreamServerResolver):
return [ssl, ssl] + list(dst)
-class AddressPriority(object):
- """
- Enum that signifies the priority of the given address when choosing the destination host.
- Higher is better (None < i)
- """
- MANUALLY_CHANGED = 3
- """user changed the target address in the ui"""
- FROM_SETTINGS = 2
- """upstream server from arguments (reverse proxy, upstream proxy or from transparent resolver)"""
- FROM_PROTOCOL = 1
- """derived from protocol (e.g. absolute-form http requests)"""
-
-
class Log:
def __init__(self, msg, level="info"):
self.msg = msg
diff --git a/libmproxy/proxy/server.py b/libmproxy/proxy/server.py
index 092eae54..58e386ab 100644
--- a/libmproxy/proxy/server.py
+++ b/libmproxy/proxy/server.py
@@ -5,7 +5,7 @@ import socket
from OpenSSL import SSL
from netlib import tcp
-from .primitives import ProxyServerError, Log, ProxyError, AddressPriority
+from .primitives import ProxyServerError, Log, ProxyError
from .connection import ClientConnection, ServerConnection
from ..protocol.handle import protocol_handler
from .. import version
@@ -76,7 +76,7 @@ class ConnectionHandler:
client_ssl, server_ssl = False, False
if self.config.get_upstream_server:
upstream_info = self.config.get_upstream_server(self.client_conn.connection)
- self.set_server_address(upstream_info[2:], AddressPriority.FROM_SETTINGS)
+ self.set_server_address(upstream_info[2:])
client_ssl, server_ssl = upstream_info[:2]
if self.check_ignore_address(self.server_conn.address):
self.log("Ignore host: %s:%s" % self.server_conn.address(), "info")
@@ -129,27 +129,22 @@ class ConnectionHandler:
else:
return False
- def set_server_address(self, address, priority):
+ def set_server_address(self, address):
"""
Sets a new server address with the given priority.
Does not re-establish either connection or SSL handshake.
"""
address = tcp.Address.wrap(address)
- if self.server_conn:
- if self.server_conn.priority > priority:
- self.log("Attempt to change server address, "
- "but priority is too low (is: %s, got: %s)" % (
- self.server_conn.priority, priority), "debug")
- return
- if self.server_conn.address == address:
- self.server_conn.priority = priority # Possibly increase priority
- return
+ # Don't reconnect to the same destination.
+ if self.server_conn and self.server_conn.address == address:
+ return
+ if self.server_conn:
self.del_server_connection()
self.log("Set new server address: %s:%s" % (address.host, address.port), "debug")
- self.server_conn = ServerConnection(address, priority)
+ self.server_conn = ServerConnection(address)
def establish_server_connection(self, ask=True):
"""
@@ -212,12 +207,11 @@ class ConnectionHandler:
def server_reconnect(self):
address = self.server_conn.address
had_ssl = self.server_conn.ssl_established
- priority = self.server_conn.priority
state = self.server_conn.state
sni = self.sni
self.log("(server reconnect follows)", "debug")
self.del_server_connection()
- self.set_server_address(address, priority)
+ self.set_server_address(address)
self.establish_server_connection()
for s in state: