diff --git a/mitmproxy/addons/view.py b/mitmproxy/addons/view.py index 8358a0453..d2ab75f3f 100644 --- a/mitmproxy/addons/view.py +++ b/mitmproxy/addons/view.py @@ -230,6 +230,17 @@ class View(collections.Sequence): self.sig_view_refresh.send(self) self.sig_store_refresh.send(self) + def clear_not_marked(self): + """ + Clears only the unmarked flows. + """ + for flow in self._store.copy().values(): + if not flow.marked: + self._store.pop(flow.id) + + self._refilter() + self.sig_store_refresh.send(self) + def add(self, f: mitmproxy.flow.Flow) -> bool: """ Adds a flow to the state. If the flow already exists, it is diff --git a/mitmproxy/tools/console/flowlist.py b/mitmproxy/tools/console/flowlist.py index b26289af6..39811ce10 100644 --- a/mitmproxy/tools/console/flowlist.py +++ b/mitmproxy/tools/console/flowlist.py @@ -35,6 +35,7 @@ def _mkhelp(): ("W", "stream flows to file"), ("X", "kill and delete flow, even if it's mid-intercept"), ("z", "clear flow list or eventlog"), + ("Z", "clear unmarked flows"), ("tab", "tab between eventlog and flow list"), ("enter", "view flow"), ("|", "run script on this flow"), @@ -354,6 +355,8 @@ class FlowListBox(urwid.ListBox): self.master.view.update(f) elif key == "z": self.master.view.clear() + elif key == "Z": + self.master.view.clear_not_marked() elif key == "e": self.master.toggle_eventlog() elif key == "g": diff --git a/test/mitmproxy/addons/test_view.py b/test/mitmproxy/addons/test_view.py index 99b12cb45..7145bfc83 100644 --- a/test/mitmproxy/addons/test_view.py +++ b/test/mitmproxy/addons/test_view.py @@ -108,6 +108,13 @@ def test_simple(): assert list(v) == [f, f3, f2] assert len(v._store) == 3 + f.marked = not f.marked + f2.marked = not f2.marked + v.clear_not_marked() + assert list(v) == [f, f2] + assert len(v) == 2 + assert len(v._store) == 2 + v.clear() assert len(v) == 0 assert len(v._store) == 0