mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-26 10:16:27 +00:00
Refine flow saving shortcuts.
"S" to save all flows. "s" to save just the current flow.
This commit is contained in:
parent
eb93cc22ce
commit
345ac0f2a0
@ -98,6 +98,8 @@ class ConnectionItem(WWrap):
|
|||||||
elif key == "R":
|
elif key == "R":
|
||||||
self.state.revert(self.flow)
|
self.state.revert(self.flow)
|
||||||
self.master.sync_list_view()
|
self.master.sync_list_view()
|
||||||
|
elif key == "s":
|
||||||
|
self.master.prompt("Save this flow: ", self.master.save_one_flow, self.flow)
|
||||||
elif key == "z":
|
elif key == "z":
|
||||||
self.master.kill_connection(self.flow)
|
self.master.kill_connection(self.flow)
|
||||||
elif key == "enter":
|
elif key == "enter":
|
||||||
@ -352,8 +354,8 @@ class ConnectionView(WWrap):
|
|||||||
elif key == "R":
|
elif key == "R":
|
||||||
self.state.revert(self.flow)
|
self.state.revert(self.flow)
|
||||||
self.master.refresh_connection(self.flow)
|
self.master.refresh_connection(self.flow)
|
||||||
elif key == "S":
|
elif key == "s":
|
||||||
self.master.prompt("Save all: ", self.save_flows)
|
self.master.prompt("Save this flow: ", self.master.save_one_flow, self.flow)
|
||||||
elif key == "v":
|
elif key == "v":
|
||||||
if self.viewing == self.REQ:
|
if self.viewing == self.REQ:
|
||||||
conn = self.flow.request
|
conn = self.flow.request
|
||||||
@ -741,10 +743,9 @@ class ConsoleMaster(controller.Master):
|
|||||||
self.nested = True
|
self.nested = True
|
||||||
self.make_view()
|
self.make_view()
|
||||||
|
|
||||||
def save_flows(self, path):
|
def _write_flows(self, path, data):
|
||||||
if not path:
|
if not path:
|
||||||
return
|
return
|
||||||
data = self.state.dump_flows()
|
|
||||||
path = os.path.expanduser(path)
|
path = os.path.expanduser(path)
|
||||||
try:
|
try:
|
||||||
f = file(path, "wb")
|
f = file(path, "wb")
|
||||||
@ -753,6 +754,14 @@ class ConsoleMaster(controller.Master):
|
|||||||
except IOError, v:
|
except IOError, v:
|
||||||
self.statusbar.message(str(v))
|
self.statusbar.message(str(v))
|
||||||
|
|
||||||
|
def save_one_flow(self, path, flow):
|
||||||
|
data = flow.dump()
|
||||||
|
return self._write_flows(path, data)
|
||||||
|
|
||||||
|
def save_flows(self, path):
|
||||||
|
data = self.state.dump_flows()
|
||||||
|
return self._write_flows(path, data)
|
||||||
|
|
||||||
def load_flows(self, path):
|
def load_flows(self, path):
|
||||||
if not path:
|
if not path:
|
||||||
return
|
return
|
||||||
@ -784,7 +793,7 @@ class ConsoleMaster(controller.Master):
|
|||||||
("q", "quit / return to connection list"),
|
("q", "quit / return to connection list"),
|
||||||
("r", "replay request"),
|
("r", "replay request"),
|
||||||
("R", "revert changes to request"),
|
("R", "revert changes to request"),
|
||||||
("S", "save flows matching current limit"),
|
("S", "save all flows matching current limit"),
|
||||||
("page up/down", "page up/down"),
|
("page up/down", "page up/down"),
|
||||||
("space", "page down"),
|
("space", "page down"),
|
||||||
("enter", "view connection"),
|
("enter", "view connection"),
|
||||||
@ -795,6 +804,7 @@ class ConsoleMaster(controller.Master):
|
|||||||
keys = [
|
keys = [
|
||||||
("C", "clear connection list"),
|
("C", "clear connection list"),
|
||||||
("d", "delete connection from view"),
|
("d", "delete connection from view"),
|
||||||
|
("s", "save this t flow"),
|
||||||
("z", "kill and delete connection, even if it's mid-intercept"),
|
("z", "kill and delete connection, even if it's mid-intercept"),
|
||||||
]
|
]
|
||||||
text.extend(format_keyvals(keys, key="key", val="text", indent=4))
|
text.extend(format_keyvals(keys, key="key", val="text", indent=4))
|
||||||
@ -803,7 +813,7 @@ class ConsoleMaster(controller.Master):
|
|||||||
keys = [
|
keys = [
|
||||||
("b", "toggle hexdump view"),
|
("b", "toggle hexdump view"),
|
||||||
("e", "edit response/request"),
|
("e", "edit response/request"),
|
||||||
("S", "save request or response"),
|
("s", "save this flow"),
|
||||||
("v", "view contents in external viewer"),
|
("v", "view contents in external viewer"),
|
||||||
("tab", "toggle response/request view"),
|
("tab", "toggle response/request view"),
|
||||||
]
|
]
|
||||||
@ -859,15 +869,15 @@ class ConsoleMaster(controller.Master):
|
|||||||
self.nested = True
|
self.nested = True
|
||||||
self.make_view()
|
self.make_view()
|
||||||
|
|
||||||
def path_prompt(self, prompt, callback):
|
def path_prompt(self, prompt, callback, *args):
|
||||||
self.statusbar.path_prompt(prompt)
|
self.statusbar.path_prompt(prompt)
|
||||||
self.view.set_focus("footer")
|
self.view.set_focus("footer")
|
||||||
self.prompting = callback
|
self.prompting = (callback, args)
|
||||||
|
|
||||||
def prompt(self, prompt, callback):
|
def prompt(self, prompt, callback, *args):
|
||||||
self.statusbar.prompt(prompt)
|
self.statusbar.prompt(prompt)
|
||||||
self.view.set_focus("footer")
|
self.view.set_focus("footer")
|
||||||
self.prompting = callback
|
self.prompting = (callback, args)
|
||||||
|
|
||||||
def prompt_onekey(self, prompt, keys, callback):
|
def prompt_onekey(self, prompt, keys, callback):
|
||||||
"""
|
"""
|
||||||
@ -899,9 +909,9 @@ class ConsoleMaster(controller.Master):
|
|||||||
def prompt_execute(self, txt=None):
|
def prompt_execute(self, txt=None):
|
||||||
if not txt:
|
if not txt:
|
||||||
txt = self.statusbar.get_edit_text()
|
txt = self.statusbar.get_edit_text()
|
||||||
p = self.prompting
|
p, args = self.prompting
|
||||||
self.prompt_done()
|
self.prompt_done()
|
||||||
msg = p(txt)
|
msg = p(txt, *args)
|
||||||
if msg:
|
if msg:
|
||||||
self.statusbar.message(msg)
|
self.statusbar.message(msg)
|
||||||
|
|
||||||
|
@ -33,6 +33,12 @@ class Flow:
|
|||||||
self.intercepting = False
|
self.intercepting = False
|
||||||
self._backup = None
|
self._backup = None
|
||||||
|
|
||||||
|
def dump(self):
|
||||||
|
data = dict(
|
||||||
|
flows = [self.get_state()]
|
||||||
|
)
|
||||||
|
return bson.dumps(data)
|
||||||
|
|
||||||
def get_state(self):
|
def get_state(self):
|
||||||
return dict(
|
return dict(
|
||||||
request = self.request.get_state() if self.request else None,
|
request = self.request.get_state() if self.request else None,
|
||||||
|
@ -78,6 +78,7 @@ if __name__ == '__main__':
|
|||||||
)
|
)
|
||||||
server = proxy.ProxyServer(options.port)
|
server = proxy.ProxyServer(options.port)
|
||||||
m = console.ConsoleMaster(server, options)
|
m = console.ConsoleMaster(server, options)
|
||||||
|
|
||||||
for i in args:
|
for i in args:
|
||||||
m.load_flows(i)
|
m.load_flows(i)
|
||||||
m.run()
|
m.run()
|
||||||
|
Loading…
Reference in New Issue
Block a user