connection -> flow in libmitmproxy/console
"Flow" is the correct term here - every connection can have multiple flows.
This commit is contained in:
parent
1af26bb915
commit
d2f5db1f37
|
@ -17,7 +17,7 @@ import mailcap, mimetypes, tempfile, os, subprocess, glob, time
|
|||
import os.path, sys
|
||||
import urwid
|
||||
from .. import controller, utils, flow
|
||||
import connlist, connview, help, common, kveditor, palettes
|
||||
import flowlist, flowview, help, common, kveditor, palettes
|
||||
|
||||
EVENTLOG_SIZE = 500
|
||||
|
||||
|
@ -317,7 +317,7 @@ class ConsoleMaster(flow.FlowMaster):
|
|||
footer_text_help = [
|
||||
('heading_key', "q"), ":back",
|
||||
]
|
||||
footer_text_connview = [
|
||||
footer_text_flowview = [
|
||||
('heading_key', "tab"), ":toggle view ",
|
||||
('heading_key', "?"), ":help ",
|
||||
('heading_key', "q"), ":back ",
|
||||
|
@ -327,7 +327,7 @@ class ConsoleMaster(flow.FlowMaster):
|
|||
self.looptime = 0
|
||||
self.options = options
|
||||
|
||||
self.conn_list_view = None
|
||||
self.flow_list_view = None
|
||||
self.set_palette()
|
||||
|
||||
r = self.set_intercept(options.intercept)
|
||||
|
@ -383,7 +383,7 @@ class ConsoleMaster(flow.FlowMaster):
|
|||
if f.error:
|
||||
s.run("error", f)
|
||||
s.run("done")
|
||||
self.refresh_connection(f)
|
||||
self.refresh_flow(f)
|
||||
self.state.last_script = path
|
||||
|
||||
def set_script(self, path):
|
||||
|
@ -396,7 +396,7 @@ class ConsoleMaster(flow.FlowMaster):
|
|||
|
||||
def toggle_eventlog(self):
|
||||
self.eventlog = not self.eventlog
|
||||
self.view_connlist()
|
||||
self.view_flowlist()
|
||||
|
||||
def _readflow(self, path):
|
||||
path = os.path.expanduser(path)
|
||||
|
@ -481,7 +481,7 @@ class ConsoleMaster(flow.FlowMaster):
|
|||
self.ui = urwid.raw_display.Screen()
|
||||
self.ui.set_terminal_properties(256)
|
||||
self.ui.register_palette(self.palette)
|
||||
self.conn_list_view = connlist.ConnectionListView(self, self.state)
|
||||
self.flow_list_view = flowlist.ConnectionListView(self, self.state)
|
||||
|
||||
self.view = None
|
||||
self.statusbar = None
|
||||
|
@ -492,7 +492,7 @@ class ConsoleMaster(flow.FlowMaster):
|
|||
self.prompting = False
|
||||
self.onekey = False
|
||||
|
||||
self.view_connlist()
|
||||
self.view_flowlist()
|
||||
|
||||
if self.server:
|
||||
slave = controller.Slave(self.masterq, self.server)
|
||||
|
@ -506,7 +506,7 @@ class ConsoleMaster(flow.FlowMaster):
|
|||
sys.exit(1)
|
||||
|
||||
self.ui.run_wrapper(self.loop)
|
||||
# If True, quit just pops out to connection list view.
|
||||
# If True, quit just pops out to flow list view.
|
||||
print >> sys.stderr, "Shutting down..."
|
||||
sys.stderr.flush()
|
||||
self.shutdown()
|
||||
|
@ -514,7 +514,7 @@ class ConsoleMaster(flow.FlowMaster):
|
|||
def focus_current(self):
|
||||
if self.currentflow:
|
||||
try:
|
||||
self.conn_list_view.set_focus(self.state.index(self.currentflow))
|
||||
self.flow_list_view.set_focus(self.state.index(self.currentflow))
|
||||
except (IndexError, ValueError):
|
||||
pass
|
||||
|
||||
|
@ -540,29 +540,29 @@ class ConsoleMaster(flow.FlowMaster):
|
|||
self.statusbar = StatusBar(self, self.footer_text_help)
|
||||
self.make_view()
|
||||
|
||||
def view_connlist(self):
|
||||
def view_flowlist(self):
|
||||
if self.ui.started:
|
||||
self.ui.clear()
|
||||
self.focus_current()
|
||||
if self.eventlog:
|
||||
self.body = connlist.BodyPile(self)
|
||||
self.body = flowlist.BodyPile(self)
|
||||
else:
|
||||
self.body = connlist.ConnectionListBox(self)
|
||||
self.body = flowlist.ConnectionListBox(self)
|
||||
self.statusbar = StatusBar(self, self.footer_text_default)
|
||||
self.header = None
|
||||
self.currentflow = None
|
||||
|
||||
self.make_view()
|
||||
self.help_context = connlist.help_context
|
||||
self.help_context = flowlist.help_context
|
||||
|
||||
def view_flow(self, flow):
|
||||
self.body = connview.ConnectionView(self, self.state, flow)
|
||||
self.header = connview.ConnectionViewHeader(self, flow)
|
||||
self.statusbar = StatusBar(self, self.footer_text_connview)
|
||||
self.body = flowview.ConnectionView(self, self.state, flow)
|
||||
self.header = flowview.ConnectionViewHeader(self, flow)
|
||||
self.statusbar = StatusBar(self, self.footer_text_flowview)
|
||||
self.currentflow = flow
|
||||
|
||||
self.make_view()
|
||||
self.help_context = connview.help_context
|
||||
self.help_context = flowview.help_context
|
||||
|
||||
def _write_flows(self, path, flows):
|
||||
self.state.last_saveload = path
|
||||
|
@ -603,7 +603,7 @@ class ConsoleMaster(flow.FlowMaster):
|
|||
except flow.FlowReadError, v:
|
||||
return v.strerror
|
||||
f.close()
|
||||
if self.conn_list_view:
|
||||
if self.flow_list_view:
|
||||
self.sync_list_view()
|
||||
self.focus_current()
|
||||
|
||||
|
@ -681,7 +681,7 @@ class ConsoleMaster(flow.FlowMaster):
|
|||
self.state.view_body_mode = common.VIEW_BODY_HEX
|
||||
elif v == "p":
|
||||
self.state.view_body_mode = common.VIEW_BODY_PRETTY
|
||||
self.refresh_connection(self.currentflow)
|
||||
self.refresh_flow(self.currentflow)
|
||||
|
||||
def drawscreen(self):
|
||||
size = self.ui.get_cols_rows()
|
||||
|
@ -693,7 +693,7 @@ class ConsoleMaster(flow.FlowMaster):
|
|||
if self.currentflow:
|
||||
self.view_flow(self.currentflow)
|
||||
else:
|
||||
self.view_connlist()
|
||||
self.view_flowlist()
|
||||
|
||||
def loop(self):
|
||||
changed = True
|
||||
|
@ -851,23 +851,23 @@ class ConsoleMaster(flow.FlowMaster):
|
|||
controller.Master.shutdown(self)
|
||||
|
||||
def sync_list_view(self):
|
||||
self.conn_list_view._modified()
|
||||
self.flow_list_view._modified()
|
||||
|
||||
def clear_connections(self):
|
||||
def clear_flows(self):
|
||||
self.state.clear()
|
||||
self.sync_list_view()
|
||||
|
||||
def delete_connection(self, f):
|
||||
def delete_flow(self, f):
|
||||
self.state.delete_flow(f)
|
||||
self.sync_list_view()
|
||||
|
||||
def refresh_connection(self, c):
|
||||
if hasattr(self.header, "refresh_connection"):
|
||||
self.header.refresh_connection(c)
|
||||
if hasattr(self.body, "refresh_connection"):
|
||||
self.body.refresh_connection(c)
|
||||
if hasattr(self.statusbar, "refresh_connection"):
|
||||
self.statusbar.refresh_connection(c)
|
||||
def refresh_flow(self, c):
|
||||
if hasattr(self.header, "refresh_flow"):
|
||||
self.header.refresh_flow(c)
|
||||
if hasattr(self.body, "refresh_flow"):
|
||||
self.body.refresh_flow(c)
|
||||
if hasattr(self.statusbar, "refresh_flow"):
|
||||
self.statusbar.refresh_flow(c)
|
||||
|
||||
def process_flow(self, f, r):
|
||||
if self.state.intercept and f.match(self.state.intercept) and not f.request.is_replay():
|
||||
|
@ -875,7 +875,7 @@ class ConsoleMaster(flow.FlowMaster):
|
|||
else:
|
||||
r._ack()
|
||||
self.sync_list_view()
|
||||
self.refresh_connection(f)
|
||||
self.refresh_flow(f)
|
||||
|
||||
def clear_events(self):
|
||||
self.eventlist[:] = []
|
||||
|
|
|
@ -4,9 +4,9 @@ import common
|
|||
def _mkhelp():
|
||||
text = []
|
||||
keys = [
|
||||
("A", "accept all intercepted connections"),
|
||||
("a", "accept this intercepted connection"),
|
||||
("C", "clear connection list or eventlog"),
|
||||
("A", "accept all intercepted flows"),
|
||||
("a", "accept this intercepted flows"),
|
||||
("C", "clear flow list or eventlog"),
|
||||
("d", "delete flow"),
|
||||
("D", "duplicate flow"),
|
||||
("e", "toggle eventlog"),
|
||||
|
@ -16,9 +16,9 @@ def _mkhelp():
|
|||
("V", "revert changes to request"),
|
||||
("w", "save all flows matching current limit"),
|
||||
("W", "save this flow"),
|
||||
("X", "kill and delete connection, even if it's mid-intercept"),
|
||||
("tab", "tab between eventlog and connection list"),
|
||||
("enter", "view connection"),
|
||||
("X", "kill and delete flow, even if it's mid-intercept"),
|
||||
("tab", "tab between eventlog and flow list"),
|
||||
("enter", "view flow"),
|
||||
("|", "run script on this flow"),
|
||||
]
|
||||
text.extend(common.format_keyvals(keys, key="key", val="text", indent=4))
|
||||
|
@ -173,7 +173,7 @@ class ConnectionListView(urwid.ListWalker):
|
|||
class ConnectionListBox(urwid.ListBox):
|
||||
def __init__(self, master):
|
||||
self.master = master
|
||||
urwid.ListBox.__init__(self, master.conn_list_view)
|
||||
urwid.ListBox.__init__(self, master.flow_list_view)
|
||||
|
||||
def keypress(self, size, key):
|
||||
key = common.shortcuts(key)
|
||||
|
@ -181,7 +181,7 @@ class ConnectionListBox(urwid.ListBox):
|
|||
self.master.accept_all()
|
||||
self.master.sync_list_view()
|
||||
elif key == "C":
|
||||
self.master.clear_connections()
|
||||
self.master.clear_flows()
|
||||
elif key == "e":
|
||||
self.master.toggle_eventlog()
|
||||
elif key == "l":
|
|
@ -6,8 +6,8 @@ from .. import utils, encoding, flow
|
|||
def _mkhelp():
|
||||
text = []
|
||||
keys = [
|
||||
("A", "accept all intercepted connections"),
|
||||
("a", "accept this intercepted connection"),
|
||||
("A", "accept all intercepted flows"),
|
||||
("a", "accept this intercepted flow"),
|
||||
("b", "save request/response body"),
|
||||
("d", "delete flow"),
|
||||
("D", "duplicate flow"),
|
||||
|
@ -48,7 +48,7 @@ class ConnectionViewHeader(common.WWrap):
|
|||
self.master, self.flow = master, f
|
||||
self.w = common.format_flow(f, False, extended=True, padding=0)
|
||||
|
||||
def refresh_connection(self, f):
|
||||
def refresh_flow(self, f):
|
||||
if f == self.flow:
|
||||
self.w = common.format_flow(f, False, extended=True, padding=0)
|
||||
|
||||
|
@ -92,7 +92,7 @@ class ConnectionView(common.WWrap):
|
|||
)
|
||||
)
|
||||
|
||||
def _view_conn_raw(self, content):
|
||||
def _view_flow_raw(self, content):
|
||||
txt = []
|
||||
for i in utils.cleanBin(content[:VIEW_CUTOFF]).splitlines():
|
||||
txt.append(
|
||||
|
@ -101,7 +101,7 @@ class ConnectionView(common.WWrap):
|
|||
self._trailer(len(content), txt)
|
||||
return txt
|
||||
|
||||
def _view_conn_binary(self, content):
|
||||
def _view_flow_binary(self, content):
|
||||
txt = []
|
||||
for offset, hexa, s in utils.hexdump(content[:VIEW_CUTOFF]):
|
||||
txt.append(urwid.Text([
|
||||
|
@ -114,7 +114,7 @@ class ConnectionView(common.WWrap):
|
|||
self._trailer(len(content), txt)
|
||||
return txt
|
||||
|
||||
def _view_conn_xmlish(self, content):
|
||||
def _view_flow_xmlish(self, content):
|
||||
txt = []
|
||||
for i in utils.pretty_xmlish(content[:VIEW_CUTOFF]):
|
||||
txt.append(
|
||||
|
@ -123,7 +123,7 @@ class ConnectionView(common.WWrap):
|
|||
self._trailer(len(content), txt)
|
||||
return txt
|
||||
|
||||
def _view_conn_json(self, lines):
|
||||
def _view_flow_json(self, lines):
|
||||
txt = []
|
||||
sofar = 0
|
||||
for i in lines:
|
||||
|
@ -136,7 +136,7 @@ class ConnectionView(common.WWrap):
|
|||
self._trailer(sum(len(i) for i in lines), txt)
|
||||
return txt
|
||||
|
||||
def _view_conn_formdata(self, content, boundary):
|
||||
def _view_flow_formdata(self, content, boundary):
|
||||
rx = re.compile(r'\bname="([^"]+)"')
|
||||
keys = []
|
||||
vals = []
|
||||
|
@ -160,7 +160,7 @@ class ConnectionView(common.WWrap):
|
|||
))
|
||||
return r
|
||||
|
||||
def _view_conn_urlencoded(self, lines):
|
||||
def _view_flow_urlencoded(self, lines):
|
||||
return common.format_keyvals(
|
||||
[(k+":", v) for (k, v) in lines],
|
||||
key = "header",
|
||||
|
@ -177,18 +177,18 @@ class ConnectionView(common.WWrap):
|
|||
if ctype and flow.HDR_FORM_URLENCODED in ctype:
|
||||
data = utils.urldecode(content)
|
||||
if data:
|
||||
return "URLEncoded form", self._view_conn_urlencoded(data)
|
||||
return "URLEncoded form", self._view_flow_urlencoded(data)
|
||||
if utils.isXML(content):
|
||||
return "Indented XML-ish", self._view_conn_xmlish(content)
|
||||
return "Indented XML-ish", self._view_flow_xmlish(content)
|
||||
elif ctype and "application/json" in ctype:
|
||||
lines = utils.pretty_json(content)
|
||||
if lines:
|
||||
return "JSON", self._view_conn_json(lines)
|
||||
return "JSON", self._view_flow_json(lines)
|
||||
elif ctype and "multipart/form-data" in ctype:
|
||||
boundary = ctype.split('boundary=')
|
||||
if len(boundary) > 1:
|
||||
return "Form data", self._view_conn_formdata(content, boundary[1].split(';')[0])
|
||||
return "", self._view_conn_raw(content)
|
||||
return "Form data", self._view_flow_formdata(content, boundary[1].split(';')[0])
|
||||
return "", self._view_flow_raw(content)
|
||||
|
||||
def _cached_conn_text(self, e, content, hdrItems, viewmode):
|
||||
txt = common.format_keyvals(
|
||||
|
@ -199,7 +199,7 @@ class ConnectionView(common.WWrap):
|
|||
if content:
|
||||
msg = ""
|
||||
if viewmode == common.VIEW_BODY_HEX:
|
||||
body = self._view_conn_binary(content)
|
||||
body = self._view_flow_binary(content)
|
||||
elif viewmode == common.VIEW_BODY_PRETTY:
|
||||
emsg = ""
|
||||
if e:
|
||||
|
@ -212,7 +212,7 @@ class ConnectionView(common.WWrap):
|
|||
if emsg:
|
||||
msg = emsg + " " + msg
|
||||
else:
|
||||
body = self._view_conn_raw(content)
|
||||
body = self._view_flow_raw(content)
|
||||
|
||||
title = urwid.AttrWrap(urwid.Columns([
|
||||
urwid.Text(
|
||||
|
@ -311,7 +311,7 @@ class ConnectionView(common.WWrap):
|
|||
self.w = self.wrap_body(common.VIEW_FLOW_RESPONSE, body)
|
||||
self.master.statusbar.redraw()
|
||||
|
||||
def refresh_connection(self, c=None):
|
||||
def refresh_flow(self, c=None):
|
||||
if c == self.flow:
|
||||
if self.state.view_flow_mode == common.VIEW_FLOW_RESPONSE and self.flow.response:
|
||||
self.view_response()
|
||||
|
@ -321,7 +321,7 @@ class ConnectionView(common.WWrap):
|
|||
def set_method_raw(self, m):
|
||||
if m:
|
||||
self.flow.request.method = m
|
||||
self.master.refresh_connection(self.flow)
|
||||
self.master.refresh_flow(self.flow)
|
||||
|
||||
def edit_method(self, m):
|
||||
if m == "e":
|
||||
|
@ -330,7 +330,7 @@ class ConnectionView(common.WWrap):
|
|||
for i in self.method_options:
|
||||
if i[1] == m:
|
||||
self.flow.request.method = i[0].upper()
|
||||
self.master.refresh_connection(self.flow)
|
||||
self.master.refresh_flow(self.flow)
|
||||
|
||||
def save_body(self, path):
|
||||
if not path:
|
||||
|
@ -352,7 +352,7 @@ class ConnectionView(common.WWrap):
|
|||
request = self.flow.request
|
||||
if not request.set_url(str(url)):
|
||||
return "Invalid URL."
|
||||
self.master.refresh_connection(self.flow)
|
||||
self.master.refresh_flow(self.flow)
|
||||
|
||||
def set_resp_code(self, code):
|
||||
response = self.flow.response
|
||||
|
@ -363,12 +363,12 @@ class ConnectionView(common.WWrap):
|
|||
import BaseHTTPServer
|
||||
if BaseHTTPServer.BaseHTTPRequestHandler.responses.has_key(int(code)):
|
||||
response.msg = BaseHTTPServer.BaseHTTPRequestHandler.responses[int(code)][0]
|
||||
self.master.refresh_connection(self.flow)
|
||||
self.master.refresh_flow(self.flow)
|
||||
|
||||
def set_resp_msg(self, msg):
|
||||
response = self.flow.response
|
||||
response.msg = msg
|
||||
self.master.refresh_connection(self.flow)
|
||||
self.master.refresh_flow(self.flow)
|
||||
|
||||
def set_headers(self, lst, conn):
|
||||
conn.headers = flow.ODict(lst)
|
||||
|
@ -405,7 +405,7 @@ class ConnectionView(common.WWrap):
|
|||
self.master.prompt_edit("Code", str(conn.code), self.set_resp_code)
|
||||
elif part == "m" and self.state.view_flow_mode == common.VIEW_FLOW_RESPONSE:
|
||||
self.master.prompt_edit("Message", conn.msg, self.set_resp_msg)
|
||||
self.master.refresh_connection(self.flow)
|
||||
self.master.refresh_flow(self.flow)
|
||||
|
||||
def _view_nextprev_flow(self, np, flow):
|
||||
try:
|
||||
|
@ -438,7 +438,7 @@ class ConnectionView(common.WWrap):
|
|||
conn = self.flow.response
|
||||
|
||||
if key == "q":
|
||||
self.master.view_connlist()
|
||||
self.master.view_flowlist()
|
||||
key = None
|
||||
elif key == "tab":
|
||||
if self.state.view_flow_mode == common.VIEW_FLOW_REQUEST:
|
||||
|
@ -456,7 +456,7 @@ class ConnectionView(common.WWrap):
|
|||
self.master.view_flow(self.flow)
|
||||
elif key == "d":
|
||||
if self.state.flow_count() == 1:
|
||||
self.master.view_connlist()
|
||||
self.master.view_flowlist()
|
||||
elif self.state.view.index(self.flow) == len(self.state.view)-1:
|
||||
self.view_prev_flow(self.flow)
|
||||
else:
|
||||
|
@ -512,10 +512,10 @@ class ConnectionView(common.WWrap):
|
|||
r = self.master.replay_request(self.flow)
|
||||
if r:
|
||||
self.master.statusbar.message(r)
|
||||
self.master.refresh_connection(self.flow)
|
||||
self.master.refresh_flow(self.flow)
|
||||
elif key == "V":
|
||||
self.state.revert(self.flow)
|
||||
self.master.refresh_connection(self.flow)
|
||||
self.master.refresh_flow(self.flow)
|
||||
elif key == "W":
|
||||
self.master.path_prompt(
|
||||
"Save this flow: ",
|
||||
|
@ -562,7 +562,7 @@ class ConnectionView(common.WWrap):
|
|||
self.encode_callback,
|
||||
conn
|
||||
)
|
||||
self.master.refresh_connection(self.flow)
|
||||
self.master.refresh_flow(self.flow)
|
||||
else:
|
||||
return key
|
||||
|
||||
|
@ -572,4 +572,4 @@ class ConnectionView(common.WWrap):
|
|||
"d": "deflate",
|
||||
}
|
||||
conn.encode(encoding_map[key])
|
||||
self.master.refresh_connection(self.flow)
|
||||
self.master.refresh_flow(self.flow)
|
|
@ -59,7 +59,7 @@ class HelpView(urwid.ListBox):
|
|||
[("text", ": disable server replay response refresh")]
|
||||
),
|
||||
|
||||
("q", "quit / return to connection list"),
|
||||
("q", "quit / return to flow list"),
|
||||
("Q", "quit without confirm prompt"),
|
||||
("R", "set reverse proxy mode"),
|
||||
("s", "set/unset script"),
|
||||
|
|
Loading…
Reference in New Issue