diff options
-rw-r--r-- | mitmproxy/addons/intercept.py | 13 | ||||
-rw-r--r-- | mitmproxy/options.py | 12 | ||||
-rw-r--r-- | mitmproxy/tools/console/consoleaddons.py | 9 | ||||
-rw-r--r-- | mitmproxy/tools/console/defaultkeys.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/addons/test_intercept.py | 2 | ||||
-rw-r--r-- | test/mitmproxy/tools/console/test_master.py | 15 |
6 files changed, 15 insertions, 38 deletions
diff --git a/mitmproxy/addons/intercept.py b/mitmproxy/addons/intercept.py index 9e1a283e..d39d1962 100644 --- a/mitmproxy/addons/intercept.py +++ b/mitmproxy/addons/intercept.py @@ -1,3 +1,5 @@ +import typing + from mitmproxy import flowfilter from mitmproxy import exceptions from mitmproxy import ctx @@ -7,6 +9,17 @@ class Intercept: def __init__(self): self.filt = None + def load(self, loader): + loader.add_option( + "intercept_active", bool, False, + "Intercept toggle" + ) + + loader.add_option( + "intercept", typing.Optional[str], None, + "Intercept filter expression." + ) + def configure(self, updated): if "intercept" in updated: if not ctx.options.intercept: diff --git a/mitmproxy/options.py b/mitmproxy/options.py index 139b197f..05332b3f 100644 --- a/mitmproxy/options.py +++ b/mitmproxy/options.py @@ -58,8 +58,6 @@ class Options(optmanager.OptManager): # because they're used by more than one addon, or because they're # embedded in the core code somehow. default_contentview = None # type: str - intercept = None # type: Optional[str] - intercept_active = None # type: bool proxyauth = None # type: Optional[str] showhost = None # type: bool verbosity = None # type: str @@ -252,16 +250,6 @@ class Options(optmanager.OptManager): ) self.add_option( - "intercept_active", bool, False, - "Intercept toggle" - ) - - self.add_option( - "intercept", Optional[str], None, - "Intercept filter expression." - ) - - self.add_option( "view_filter", Optional[str], None, "Limit which flows are displayed." ) diff --git a/mitmproxy/tools/console/consoleaddons.py b/mitmproxy/tools/console/consoleaddons.py index c73eda42..9856e80f 100644 --- a/mitmproxy/tools/console/consoleaddons.py +++ b/mitmproxy/tools/console/consoleaddons.py @@ -110,15 +110,6 @@ class ConsoleAddon: """ return ["single", "vertical", "horizontal"] - @command.command("console.intercept.toggle") - def intercept_toggle(self) -> None: - """ - Toggles interception on/off leaving intercept filters intact. - """ - ctx.options.update( - intercept_active = not ctx.options.intercept_active - ) - @command.command("console.layout.cycle") def layout_cycle(self) -> None: """ diff --git a/mitmproxy/tools/console/defaultkeys.py b/mitmproxy/tools/console/defaultkeys.py index c7876288..7f65c1f7 100644 --- a/mitmproxy/tools/console/defaultkeys.py +++ b/mitmproxy/tools/console/defaultkeys.py @@ -26,7 +26,7 @@ def map(km): km.add("ctrl f", "console.nav.pagedown", ["global"], "Page down") km.add("ctrl b", "console.nav.pageup", ["global"], "Page up") - km.add("I", "console.intercept.toggle", ["global"], "Toggle intercept") + km.add("I", "set intercept_active=toggle", ["global"], "Toggle intercept") km.add("i", "console.command.set intercept", ["global"], "Set intercept") km.add("W", "console.command.set save_stream_file", ["global"], "Stream to file") km.add("A", "flow.resume @all", ["flowlist", "flowview"], "Resume all intercepted flows") diff --git a/test/mitmproxy/addons/test_intercept.py b/test/mitmproxy/addons/test_intercept.py index d9598101..b3d24626 100644 --- a/test/mitmproxy/addons/test_intercept.py +++ b/test/mitmproxy/addons/test_intercept.py @@ -8,7 +8,7 @@ from mitmproxy.test import tflow def test_simple(): r = intercept.Intercept() - with taddons.context() as tctx: + with taddons.context(r) as tctx: assert not r.filt tctx.configure(r, intercept="~q") assert r.filt diff --git a/test/mitmproxy/tools/console/test_master.py b/test/mitmproxy/tools/console/test_master.py index 6ea61991..5be035e8 100644 --- a/test/mitmproxy/tools/console/test_master.py +++ b/test/mitmproxy/tools/console/test_master.py @@ -1,8 +1,6 @@ import urwid from mitmproxy import options -from mitmproxy.test import tflow -from mitmproxy.test import tutils from mitmproxy.tools import console from ... import tservers @@ -24,16 +22,3 @@ class TestMaster(tservers.MasterTest): except urwid.ExitMainLoop: pass assert len(m.view) == i - - def test_intercept(self): - """regression test for https://github.com/mitmproxy/mitmproxy/issues/1605""" - m = self.mkmaster(intercept="~b bar") - f = tflow.tflow(req=tutils.treq(content=b"foo")) - m.addons.handle_lifecycle("request", f) - assert not m.view[0].intercepted - f = tflow.tflow(req=tutils.treq(content=b"bar")) - m.addons.handle_lifecycle("request", f) - assert m.view[1].intercepted - f = tflow.tflow(resp=tutils.tresp(content=b"bar")) - m.addons.handle_lifecycle("request", f) - assert m.view[2].intercepted |