fix bugs, expose timestamp information to console ui
This commit is contained in:
parent
80683e77bc
commit
cb397ec788
|
@ -197,7 +197,7 @@ class StatusBar(common.WWrap):
|
||||||
]
|
]
|
||||||
|
|
||||||
if self.master.server.bound:
|
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:
|
else:
|
||||||
boundaddr = ""
|
boundaddr = ""
|
||||||
t.extend(self.get_status())
|
t.extend(self.get_status())
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import urwid
|
import urwid
|
||||||
import common
|
import common
|
||||||
|
from .. import utils
|
||||||
|
|
||||||
footer = [
|
footer = [
|
||||||
('heading_key', "q"), ":back ",
|
('heading_key', "q"), ":back ",
|
||||||
|
@ -33,8 +34,17 @@ class FlowDetailsView(urwid.ListBox):
|
||||||
title = urwid.AttrWrap(title, "heading")
|
title = urwid.AttrWrap(title, "heading")
|
||||||
text.append(title)
|
text.append(title)
|
||||||
|
|
||||||
if self.flow.response:
|
if self.flow.server_conn:
|
||||||
c = self.flow.response.cert
|
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:
|
if c:
|
||||||
text.append(urwid.Text([("head", "Server Certificate:")]))
|
text.append(urwid.Text([("head", "Server Certificate:")]))
|
||||||
parts = [
|
parts = [
|
||||||
|
@ -43,19 +53,13 @@ class FlowDetailsView(urwid.ListBox):
|
||||||
["Valid to", str(c.notafter)],
|
["Valid to", str(c.notafter)],
|
||||||
["Valid from", str(c.notbefore)],
|
["Valid from", str(c.notbefore)],
|
||||||
["Serial", str(c.serial)],
|
["Serial", str(c.serial)],
|
||||||
]
|
|
||||||
|
|
||||||
parts.append(
|
|
||||||
[
|
[
|
||||||
"Subject",
|
"Subject",
|
||||||
urwid.BoxAdapter(
|
urwid.BoxAdapter(
|
||||||
urwid.ListBox(common.format_keyvals(c.subject, key="highlight", val="text")),
|
urwid.ListBox(common.format_keyvals(c.subject, key="highlight", val="text")),
|
||||||
len(c.subject)
|
len(c.subject)
|
||||||
)
|
)
|
||||||
]
|
],
|
||||||
)
|
|
||||||
|
|
||||||
parts.append(
|
|
||||||
[
|
[
|
||||||
"Issuer",
|
"Issuer",
|
||||||
urwid.BoxAdapter(
|
urwid.BoxAdapter(
|
||||||
|
@ -63,7 +67,7 @@ class FlowDetailsView(urwid.ListBox):
|
||||||
len(c.issuer)
|
len(c.issuer)
|
||||||
)
|
)
|
||||||
]
|
]
|
||||||
)
|
]
|
||||||
|
|
||||||
if c.altnames:
|
if c.altnames:
|
||||||
parts.append(
|
parts.append(
|
||||||
|
@ -78,9 +82,10 @@ class FlowDetailsView(urwid.ListBox):
|
||||||
text.append(urwid.Text([("head", "Client Connection:")]))
|
text.append(urwid.Text([("head", "Client Connection:")]))
|
||||||
cc = self.flow.client_conn
|
cc = self.flow.client_conn
|
||||||
parts = [
|
parts = [
|
||||||
["Address", "%s:%s"%tuple(cc.address)],
|
["Address", "%s:%s" % cc.address()],
|
||||||
["Requests", "%s"%cc.requestcount],
|
["Start time", utils.format_timestamp(cc.timestamp_start)],
|
||||||
["Closed", "%s"%cc.close],
|
# ["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))
|
text.extend(common.format_keyvals(parts, key="key", val="text", indent=4))
|
||||||
|
|
||||||
|
|
|
@ -198,7 +198,7 @@ class FDomain(_Rex):
|
||||||
code = "d"
|
code = "d"
|
||||||
help = "Domain"
|
help = "Domain"
|
||||||
def __call__(self, f):
|
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):
|
class FUrl(_Rex):
|
||||||
|
|
|
@ -35,11 +35,11 @@ class AppRegistry:
|
||||||
"""
|
"""
|
||||||
Returns an WSGIAdaptor instance if request matches an app, or None.
|
Returns an WSGIAdaptor instance if request matches an app, or None.
|
||||||
"""
|
"""
|
||||||
if (request.host, request.port) in self.apps:
|
if (request.get_host(), request.get_port()) in self.apps:
|
||||||
return self.apps[(request.host, request.port)]
|
return self.apps[(request.get_host(), request.get_port())]
|
||||||
if "host" in request.headers:
|
if "host" in request.headers:
|
||||||
host = request.headers["host"][0]
|
host = request.headers["host"][0]
|
||||||
return self.apps.get((host, request.port), None)
|
return self.apps.get((host, request.get_port()), None)
|
||||||
|
|
||||||
|
|
||||||
class ReplaceHooks:
|
class ReplaceHooks:
|
||||||
|
|
|
@ -35,9 +35,9 @@ class TemporaryServerChangeMixin(object):
|
||||||
without any need to expose the ConnectionHandler to the Flow.
|
without any need to expose the ConnectionHandler to the Flow.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def change_server(self):
|
def change_server(self, address, ssl):
|
||||||
self._backup_server = True
|
self._backup_server = True
|
||||||
raise NotImplementedError
|
raise NotImplementedError("You must not change host port port.")
|
||||||
|
|
||||||
def restore_server(self):
|
def restore_server(self):
|
||||||
if not hasattr(self,"_backup_server"):
|
if not hasattr(self,"_backup_server"):
|
||||||
|
|
|
@ -735,7 +735,7 @@ class HTTPFlow(Flow):
|
||||||
"""@type: HTTPRequest"""
|
"""@type: HTTPRequest"""
|
||||||
self.response = None
|
self.response = None
|
||||||
"""@type: HTTPResponse"""
|
"""@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?
|
self.intercepting = False # FIXME: Should that rather be an attribute of Flow?
|
||||||
|
|
||||||
|
@ -880,6 +880,9 @@ class HTTPHandler(ProtocolHandler, TemporaryServerChangeMixin):
|
||||||
else:
|
else:
|
||||||
flow.response = self.get_response_from_server(flow.request)
|
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()])
|
self.c.log("response", [flow.response._assemble_first_line()])
|
||||||
response_reply = self.c.channel.ask("response" if LEGACY else "httpresponse",
|
response_reply = self.c.channel.ask("response" if LEGACY else "httpresponse",
|
||||||
flow.response if LEGACY else flow)
|
flow.response if LEGACY else flow)
|
||||||
|
@ -898,7 +901,6 @@ class HTTPHandler(ProtocolHandler, TemporaryServerChangeMixin):
|
||||||
if flow.request.form_in == "authority":
|
if flow.request.form_in == "authority":
|
||||||
self.ssl_upgrade(flow.request)
|
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,
|
self.restore_server() # If the user has changed the target server on this connection,
|
||||||
# restore the original target server
|
# restore the original target server
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -27,7 +27,7 @@ class TestDumpMaster:
|
||||||
cc = req.flow.client_conn
|
cc = req.flow.client_conn
|
||||||
cc.reply = mock.MagicMock()
|
cc.reply = mock.MagicMock()
|
||||||
m.handle_clientconnect(cc)
|
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()
|
sc.reply = mock.MagicMock()
|
||||||
m.handle_serverconnection(sc)
|
m.handle_serverconnection(sc)
|
||||||
m.handle_request(req)
|
m.handle_request(req)
|
||||||
|
|
|
@ -13,8 +13,7 @@ def test_app_registry():
|
||||||
ar.add("foo", "domain", 80)
|
ar.add("foo", "domain", 80)
|
||||||
|
|
||||||
r = tutils.treq()
|
r = tutils.treq()
|
||||||
r.host = "domain"
|
r.set_url("http://domain:80/")
|
||||||
r.port = 80
|
|
||||||
assert ar.get(r)
|
assert ar.get(r)
|
||||||
|
|
||||||
r.port = 81
|
r.port = 81
|
||||||
|
@ -587,7 +586,7 @@ class TestFlowMaster:
|
||||||
req = tutils.treq()
|
req = tutils.treq()
|
||||||
fm.handle_clientconnect(req.flow.client_conn)
|
fm.handle_clientconnect(req.flow.client_conn)
|
||||||
assert fm.scripts[0].ns["log"][-1] == "clientconnect"
|
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()
|
sc.reply = controller.DummyReply()
|
||||||
fm.handle_serverconnection(sc)
|
fm.handle_serverconnection(sc)
|
||||||
assert fm.scripts[0].ns["log"][-1] == "serverconnect"
|
assert fm.scripts[0].ns["log"][-1] == "serverconnect"
|
||||||
|
|
Loading…
Reference in New Issue