aboutsummaryrefslogtreecommitdiffstats
path: root/libmproxy/protocol
diff options
context:
space:
mode:
authorMaximilian Hils <git@maximilianhils.com>2014-09-08 14:32:42 +0200
committerMaximilian Hils <git@maximilianhils.com>2014-09-08 14:32:42 +0200
commitd06b4bfa4e4cc51e903b49e246d7771726a3e3a4 (patch)
tree23b215550d09202b987540485c8bbea25ee96f46 /libmproxy/protocol
parent6dbe431c5e680d1c7f693a4c7bb7f3f65314c5c6 (diff)
downloadmitmproxy-d06b4bfa4e4cc51e903b49e246d7771726a3e3a4.tar.gz
mitmproxy-d06b4bfa4e4cc51e903b49e246d7771726a3e3a4.tar.bz2
mitmproxy-d06b4bfa4e4cc51e903b49e246d7771726a3e3a4.zip
remove proxy mode abstraction: always be clear which mode we are in
Diffstat (limited to 'libmproxy/protocol')
-rw-r--r--libmproxy/protocol/http.py37
1 files changed, 18 insertions, 19 deletions
diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py
index 3bd1f3c1..35c5611f 100644
--- a/libmproxy/protocol/http.py
+++ b/libmproxy/protocol/http.py
@@ -865,8 +865,8 @@ class HTTPHandler(ProtocolHandler):
"""
def __init__(self, c):
super(HTTPHandler, self).__init__(c)
- self.expected_form_in = c.config.http_form_in
- self.expected_form_out = c.config.http_form_out
+ self.expected_form_in = c.config.mode.http_form_in
+ self.expected_form_out = c.config.mode.http_form_out
self.skip_authentication = False
def handle_messages(self):
@@ -1072,20 +1072,19 @@ class HTTPHandler(ProtocolHandler):
if self.c.client_conn.ssl_established:
raise http.HttpError(400, "Must not CONNECT on already encrypted connection")
- if self.expected_form_in == "absolute":
- if not self.c.config.get_upstream_server: # Regular mode
- self.c.set_server_address((request.host, request.port))
- flow.server_conn = self.c.server_conn # Update server_conn attribute on the flow
- self.c.establish_server_connection()
- self.c.client_conn.send(
- 'HTTP/1.1 200 Connection established\r\n' +
- 'Content-Length: 0\r\n' +
- ('Proxy-agent: %s\r\n' % self.c.server_version) +
- '\r\n'
- )
- return self.process_connect_request(self.c.server_conn.address)
- else: # upstream proxy mode
- return None
+ if self.c.config.mode == "regular":
+ self.c.set_server_address((request.host, request.port))
+ flow.server_conn = self.c.server_conn # Update server_conn attribute on the flow
+ self.c.establish_server_connection()
+ self.c.client_conn.send(
+ 'HTTP/1.1 200 Connection established\r\n' +
+ 'Content-Length: 0\r\n' +
+ ('Proxy-agent: %s\r\n' % self.c.server_version) +
+ '\r\n'
+ )
+ return self.process_connect_request(self.c.server_conn.address)
+ elif self.c.config.mode == "upstream":
+ return None
else:
pass # CONNECT should never occur if we don't expect absolute-form requests
@@ -1113,7 +1112,7 @@ class HTTPHandler(ProtocolHandler):
ssl = (flow.request.scheme == "https")
- if self.c.config.http_form_in == self.c.config.http_form_out == "absolute": # Upstream Proxy mode
+ if self.c.config.mode == "upstream":
# The connection to the upstream proxy may have a state we may need to take into account.
connected_to = None
@@ -1223,8 +1222,8 @@ class RequestReplayThread(threading.Thread):
form_out_backup = r.form_out
try:
# In all modes, we directly connect to the server displayed
- if self.config.http_form_out == "absolute": # form_out == absolute -> forward mode
- server_address = self.config.get_upstream_server(self.flow.client_conn)[2:]
+ if self.config.mode == "upstream":
+ server_address = self.config.mode.get_upstream_server(self.flow.client_conn)[2:]
server = ServerConnection(server_address)
server.connect()
if r.scheme == "https":