fix bugs, expose timestamp information to console ui

This commit is contained in:
Maximilian Hils 2014-02-06 00:53:39 +01:00
parent 80683e77bc
commit cb397ec788
8 changed files with 32 additions and 26 deletions

View File

@ -197,7 +197,7 @@ class StatusBar(common.WWrap):
]
if self.master.server.bound:
boundaddr = "[%s:%s]"%(self.master.server.address() or "*", self.master.server.address.port)
boundaddr = "[%s:%s]"%(self.master.server.address.host or "*", self.master.server.address.port)
else:
boundaddr = ""
t.extend(self.get_status())

View File

@ -1,5 +1,6 @@
import urwid
import common
from .. import utils
footer = [
('heading_key', "q"), ":back ",
@ -33,8 +34,17 @@ class FlowDetailsView(urwid.ListBox):
title = urwid.AttrWrap(title, "heading")
text.append(title)
if self.flow.response:
c = self.flow.response.cert
if self.flow.server_conn:
text.append(urwid.Text([("head", "Server Connection:")]))
sc = self.flow.server_conn
parts = [
["Address", "%s:%s" % sc.peername],
["Start time", utils.format_timestamp(sc.timestamp_start)],
["End time", utils.format_timestamp(sc.timestamp_end) if sc.timestamp_end else "active"],
]
text.extend(common.format_keyvals(parts, key="key", val="text", indent=4))
c = self.flow.server_conn.cert
if c:
text.append(urwid.Text([("head", "Server Certificate:")]))
parts = [
@ -43,19 +53,13 @@ class FlowDetailsView(urwid.ListBox):
["Valid to", str(c.notafter)],
["Valid from", str(c.notbefore)],
["Serial", str(c.serial)],
]
parts.append(
[
"Subject",
urwid.BoxAdapter(
urwid.ListBox(common.format_keyvals(c.subject, key="highlight", val="text")),
len(c.subject)
)
]
)
parts.append(
],
[
"Issuer",
urwid.BoxAdapter(
@ -63,7 +67,7 @@ class FlowDetailsView(urwid.ListBox):
len(c.issuer)
)
]
)
]
if c.altnames:
parts.append(
@ -78,9 +82,10 @@ class FlowDetailsView(urwid.ListBox):
text.append(urwid.Text([("head", "Client Connection:")]))
cc = self.flow.client_conn
parts = [
["Address", "%s:%s"%tuple(cc.address)],
["Requests", "%s"%cc.requestcount],
["Closed", "%s"%cc.close],
["Address", "%s:%s" % cc.address()],
["Start time", utils.format_timestamp(cc.timestamp_start)],
# ["Requests", "%s"%cc.requestcount],
["End time", utils.format_timestamp(cc.timestamp_end) if cc.timestamp_end else "active"],
]
text.extend(common.format_keyvals(parts, key="key", val="text", indent=4))

View File

@ -198,7 +198,7 @@ class FDomain(_Rex):
code = "d"
help = "Domain"
def __call__(self, f):
return bool(re.search(self.expr, f.request.host or f.server_conn.address.host, re.IGNORECASE))
return bool(re.search(self.expr, f.request.get_host(), re.IGNORECASE))
class FUrl(_Rex):

View File

@ -35,11 +35,11 @@ class AppRegistry:
"""
Returns an WSGIAdaptor instance if request matches an app, or None.
"""
if (request.host, request.port) in self.apps:
return self.apps[(request.host, request.port)]
if (request.get_host(), request.get_port()) in self.apps:
return self.apps[(request.get_host(), request.get_port())]
if "host" in request.headers:
host = request.headers["host"][0]
return self.apps.get((host, request.port), None)
return self.apps.get((host, request.get_port()), None)
class ReplaceHooks:

View File

@ -35,9 +35,9 @@ class TemporaryServerChangeMixin(object):
without any need to expose the ConnectionHandler to the Flow.
"""
def change_server(self):
def change_server(self, address, ssl):
self._backup_server = True
raise NotImplementedError
raise NotImplementedError("You must not change host port port.")
def restore_server(self):
if not hasattr(self,"_backup_server"):

View File

@ -735,7 +735,7 @@ class HTTPFlow(Flow):
"""@type: HTTPRequest"""
self.response = None
"""@type: HTTPResponse"""
self.change_server = None # Used by flow.request.set_url to change the server address
self.change_server = change_server # Used by flow.request.set_url to change the server address
self.intercepting = False # FIXME: Should that rather be an attribute of Flow?
@ -880,6 +880,9 @@ class HTTPHandler(ProtocolHandler, TemporaryServerChangeMixin):
else:
flow.response = self.get_response_from_server(flow.request)
flow.server_conn = self.c.server_conn # no further manipulation of self.c.server_conn beyond this point.
# we can safely set it as the final attribute valueh here.
self.c.log("response", [flow.response._assemble_first_line()])
response_reply = self.c.channel.ask("response" if LEGACY else "httpresponse",
flow.response if LEGACY else flow)
@ -898,7 +901,6 @@ class HTTPHandler(ProtocolHandler, TemporaryServerChangeMixin):
if flow.request.form_in == "authority":
self.ssl_upgrade(flow.request)
flow.server_conn = self.c.server_conn
self.restore_server() # If the user has changed the target server on this connection,
# restore the original target server
return True

View File

@ -27,7 +27,7 @@ class TestDumpMaster:
cc = req.flow.client_conn
cc.reply = mock.MagicMock()
m.handle_clientconnect(cc)
sc = proxy.ServerConnection((req.host, req.port), None)
sc = proxy.ServerConnection((req.get_host(), req.get_port()), None)
sc.reply = mock.MagicMock()
m.handle_serverconnection(sc)
m.handle_request(req)

View File

@ -13,8 +13,7 @@ def test_app_registry():
ar.add("foo", "domain", 80)
r = tutils.treq()
r.host = "domain"
r.port = 80
r.set_url("http://domain:80/")
assert ar.get(r)
r.port = 81
@ -587,7 +586,7 @@ class TestFlowMaster:
req = tutils.treq()
fm.handle_clientconnect(req.flow.client_conn)
assert fm.scripts[0].ns["log"][-1] == "clientconnect"
sc = proxy.ServerConnection((req.host, req.port), None)
sc = proxy.ServerConnection((req.get_host(), req.get_port()), None)
sc.reply = controller.DummyReply()
fm.handle_serverconnection(sc)
assert fm.scripts[0].ns["log"][-1] == "serverconnect"