mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-02-02 00:05:27 +00:00
Move intercept options to addon
As part of this, we zap an un-needed console command and use a boolean toggle setter instead. Also remove an ancient regression test that breaks encapsulation.
This commit is contained in:
parent
93c49c47ae
commit
f49aae312f
@ -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:
|
||||
|
@ -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
|
||||
@ -251,16 +249,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."
|
||||
|
@ -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:
|
||||
"""
|
||||
|
@ -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")
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user