diff options
-rw-r--r-- | mitmproxy/addons/core.py | 15 | ||||
-rw-r--r-- | mitmproxy/tools/console/flowlist.py | 9 | ||||
-rw-r--r-- | mitmproxy/tools/console/master.py | 1 | ||||
-rw-r--r-- | test/mitmproxy/addons/test_core.py | 11 |
4 files changed, 28 insertions, 8 deletions
diff --git a/mitmproxy/addons/core.py b/mitmproxy/addons/core.py index 3530b108..b482edbb 100644 --- a/mitmproxy/addons/core.py +++ b/mitmproxy/addons/core.py @@ -63,4 +63,19 @@ class Core: if f.killable: f.kill() updated.append(f) + ctx.log.alert("Killed %s flows." % len(updated)) + ctx.master.addons.trigger("update", updated) + + # FIXME: this will become view.revert later + @command.command("flow.revert") + def revert(self, flows: typing.Sequence[flow.Flow]) -> None: + """ + Revert flow changes. + """ + updated = [] + for f in flows: + if f.modified(): + f.revert() + updated.append(f) + ctx.log.alert("Reverted %s flows." % len(updated)) ctx.master.addons.trigger("update", updated) diff --git a/mitmproxy/tools/console/flowlist.py b/mitmproxy/tools/console/flowlist.py index bf8e2eee..2b89915f 100644 --- a/mitmproxy/tools/console/flowlist.py +++ b/mitmproxy/tools/console/flowlist.py @@ -141,14 +141,7 @@ class FlowItem(urwid.WidgetWrap): def keypress(self, xxx_todo_changeme, key): (maxcol,) = xxx_todo_changeme key = common.shortcuts(key) - if key == "V": - if not self.flow.modified(): - signals.status_message.send(message="Flow not modified.") - return - self.flow.revert() - signals.flowlist_change.send(self) - signals.status_message.send(message="Reverted.") - elif key == "|": + if key == "|": signals.status_prompt_path.send( prompt = "Send flow to script", callback = self.master.run_script_once, diff --git a/mitmproxy/tools/console/master.py b/mitmproxy/tools/console/master.py index de58f43f..638a3d34 100644 --- a/mitmproxy/tools/console/master.py +++ b/mitmproxy/tools/console/master.py @@ -166,6 +166,7 @@ def default_keymap(km): km.add("v", "set console_order_reversed=toggle", context="flowlist") km.add("U", "flow.mark @all false", context="flowlist") km.add("w", "console.command 'save.file @shown '", context="flowlist") + km.add("V", "flow.revert @focus", context="flowlist") km.add("X", "flow.kill @focus", context="flowlist") km.add("z", "view.remove @all", context="flowlist") km.add("Z", "view.remove @hidden", context="flowlist") diff --git a/test/mitmproxy/addons/test_core.py b/test/mitmproxy/addons/test_core.py index 25fefb5d..64d0fa19 100644 --- a/test/mitmproxy/addons/test_core.py +++ b/test/mitmproxy/addons/test_core.py @@ -50,3 +50,14 @@ def test_kill(): assert f.killable sa.kill([f]) assert not f.killable + + +def test_revert(): + sa = core.Core() + with taddons.context(): + f = tflow.tflow() + f.backup() + f.request.content = b"bar" + assert f.modified() + sa.revert([f]) + assert not f.modified() |