remove _flow_map from state, improve logging
This commit is contained in:
parent
30a44cbb41
commit
7d96ff00ef
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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()
|
|
@ -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
|
||||
|
|
|
@ -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):
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue