From 7d96ff00efd80b11ab35f7f1c9c7dd6aff9c9032 Mon Sep 17 00:00:00 2001 From: Maximilian Hils Date: Fri, 31 Jan 2014 03:01:51 +0100 Subject: remove _flow_map from state, improve logging --- libmproxy/flow.py | 16 +++------------- libmproxy/protocol/http.py | 1 + libmproxy/protocol/tcp.py | 2 +- libmproxy/proxy.py | 16 ++++++++++++++-- test/test_console.py | 2 +- test/test_flow.py | 4 ---- 6 files changed, 20 insertions(+), 21 deletions(-) diff --git a/libmproxy/flow.py b/libmproxy/flow.py index d48c35dc..4032461d 100644 --- a/libmproxy/flow.py +++ b/libmproxy/flow.py @@ -236,7 +236,6 @@ class ServerPlaybackState: return l.pop(0) - class StickyCookieState: def __init__(self, flt): """ @@ -306,7 +305,6 @@ class StickyAuthState: class State(object): def __init__(self): - self._flow_map = {} self._flow_list = [] self.view = [] @@ -320,7 +318,7 @@ class State(object): return self._limit_txt def flow_count(self): - return len(self._flow_map) + return len(self._flow_list) def index(self, f): return self._flow_list.index(f) @@ -338,8 +336,6 @@ class State(object): """ f = req.flow self._flow_list.append(f) - self._flow_map[req] = f - assert len(self._flow_list) == len(self._flow_map) if f.match(self._limit): self.view.append(f) return f @@ -348,10 +344,9 @@ class State(object): """ Add a response to the state. Returns the matching flow. """ - f = self._flow_map.get(resp.flow) + f = resp.flow if not f: return False - f.response = resp if f.match(self._limit) and not f in self.view: self.view.append(f) return f @@ -361,18 +356,15 @@ class State(object): Add an error response to the state. Returns the matching flow, or None if there isn't one. """ - f = self._flow_map.get(err.flow) + f = err.flow if not f: return None - f.error = err if f.match(self._limit) and not f in self.view: self.view.append(f) return f def load_flows(self, flows): self._flow_list.extend(flows) - for i in flows: - self._flow_map[i.request] = i self.recalculate_view() def set_limit(self, txt): @@ -405,8 +397,6 @@ class State(object): self.view = self._flow_list[:] def delete_flow(self, f): - if f.request in self._flow_map: - del self._flow_map[f.request] self._flow_list.remove(f) if f in self.view: self.view.remove(f) diff --git a/libmproxy/protocol/http.py b/libmproxy/protocol/http.py index fcfc53b8..29cdf446 100644 --- a/libmproxy/protocol/http.py +++ b/libmproxy/protocol/http.py @@ -874,6 +874,7 @@ class HTTPFlow(Flow): c += self.response.replace(pattern, repl, *args, **kwargs) return c + class HttpAuthenticationError(Exception): def __init__(self, auth_headers=None): self.auth_headers = auth_headers diff --git a/libmproxy/protocol/tcp.py b/libmproxy/protocol/tcp.py index 4441d2f0..406a6f7b 100644 --- a/libmproxy/protocol/tcp.py +++ b/libmproxy/protocol/tcp.py @@ -54,6 +54,6 @@ class TCPHandler(ProtocolHandler): self.c.close = True break - self.c.log("%s %s" % (direction, dst_str), ["\r\n" + data]) + self.c.log("%s %s\r\n%s" % (direction, dst_str,data)) dst.wfile.write(data) dst.wfile.flush() \ No newline at end of file diff --git a/libmproxy/proxy.py b/libmproxy/proxy.py index e63573fb..e69bb6da 100644 --- a/libmproxy/proxy.py +++ b/libmproxy/proxy.py @@ -291,8 +291,20 @@ class ConnectionHandler: A protocol handler must raise a ConnTypeChanged exception if it detects that this is happening """ # TODO: Implement SSL pass-through handling and change conntype - if self.server_conn.address.host == "news.ycombinator.com": + passthrough = ["echo.websocket.org", + "174.129.224.73" # echo.websocket.org, transparent mode + ] + if self.server_conn.address.host in passthrough or self.sni in passthrough: self.conntype = "tcp" + return + + if client or server: + subs = [] + if client: + subs.append("with client") + if server: + subs.append("with server (sni: %s)" % self.sni) + self.log("Establish SSL", subs) if server: if self.server_conn.ssl_established: @@ -307,7 +319,7 @@ class ConnectionHandler: def server_reconnect(self, no_ssl=False): had_ssl, sni = self.server_conn.ssl_established, self.sni - self.log("server reconnect (ssl: %s, sni: %s)" % (had_ssl, sni)) + self.log("(server reconnect follows)") self.establish_server_connection(self.server_conn.address()) if had_ssl and not no_ssl: self.sni = sni diff --git a/test/test_console.py b/test/test_console.py index 4fd9bb9f..20534177 100644 --- a/test/test_console.py +++ b/test/test_console.py @@ -16,7 +16,7 @@ class TestConsoleState: """ c = console.ConsoleState() f = self._add_request(c) - assert f.request in c._flow_map + assert f in c._flow_list assert c.get_focus() == (f, 0) def test_focus(self): diff --git a/test/test_flow.py b/test/test_flow.py index aec04152..42118e36 100644 --- a/test/test_flow.py +++ b/test/test_flow.py @@ -355,23 +355,19 @@ class TestState: f = c.add_request(req) assert f assert c.flow_count() == 1 - assert c._flow_map.get(req) assert c.active_flow_count() == 1 newreq = tutils.treq() assert c.add_request(newreq) - assert c._flow_map.get(newreq) assert c.active_flow_count() == 2 resp = tutils.tresp(req) assert c.add_response(resp) assert c.flow_count() == 2 - assert c._flow_map.get(resp.request) assert c.active_flow_count() == 1 unseen_resp = tutils.tresp() assert not c.add_response(unseen_resp) - assert not c._flow_map.get(unseen_resp.request) assert c.active_flow_count() == 1 resp = tutils.tresp(newreq) -- cgit v1.2.3