mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
Split dumper_filter off from view_filter
These don't even do the same thing.
This commit is contained in:
parent
2fb85553cc
commit
e5cdc20eb8
@ -47,14 +47,18 @@ class Dumper:
|
|||||||
"The default content view mode.",
|
"The default content view mode.",
|
||||||
choices = [i.name.lower() for i in contentviews.views]
|
choices = [i.name.lower() for i in contentviews.views]
|
||||||
)
|
)
|
||||||
|
loader.add_option(
|
||||||
|
"dumper_filter", typing.Optional[str], None,
|
||||||
|
"Limit which flows are dumped."
|
||||||
|
)
|
||||||
|
|
||||||
def configure(self, updated):
|
def configure(self, updated):
|
||||||
if "view_filter" in updated:
|
if "dumper_filter" in updated:
|
||||||
if ctx.options.view_filter:
|
if ctx.options.dumper_filter:
|
||||||
self.filter = flowfilter.parse(ctx.options.view_filter)
|
self.filter = flowfilter.parse(ctx.options.dumper_filter)
|
||||||
if not self.filter:
|
if not self.filter:
|
||||||
raise exceptions.OptionsError(
|
raise exceptions.OptionsError(
|
||||||
"Invalid filter expression: %s" % ctx.options.view_filter
|
"Invalid filter expression: %s" % ctx.options.dumper_filter
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
self.filter = None
|
self.filter = None
|
||||||
|
@ -146,6 +146,10 @@ class View(collections.Sequence):
|
|||||||
self.settings = Settings(self)
|
self.settings = Settings(self)
|
||||||
|
|
||||||
def load(self, loader):
|
def load(self, loader):
|
||||||
|
loader.add_option(
|
||||||
|
"view_filter", typing.Optional[str], None,
|
||||||
|
"Limit the view to matching flows."
|
||||||
|
)
|
||||||
loader.add_option(
|
loader.add_option(
|
||||||
"view_order", str, "time",
|
"view_order", str, "time",
|
||||||
"Flow sort order.",
|
"Flow sort order.",
|
||||||
|
@ -41,11 +41,6 @@ class Options(optmanager.OptManager):
|
|||||||
upstream_cert = None # type: bool
|
upstream_cert = None # type: bool
|
||||||
websocket = None # type: bool
|
websocket = None # type: bool
|
||||||
|
|
||||||
# FIXME: Options that must be migrated to addons, but are complicated
|
|
||||||
# because they're used by more than one addon, or because they're
|
|
||||||
# embedded in the core code somehow.
|
|
||||||
view_filter = None # type: Optional[str]
|
|
||||||
|
|
||||||
def __init__(self, **kwargs) -> None:
|
def __init__(self, **kwargs) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.add_option(
|
self.add_option(
|
||||||
@ -212,9 +207,4 @@ class Options(optmanager.OptManager):
|
|||||||
"""
|
"""
|
||||||
)
|
)
|
||||||
|
|
||||||
self.add_option(
|
|
||||||
"view_filter", Optional[str], None,
|
|
||||||
"Limit which flows are displayed."
|
|
||||||
)
|
|
||||||
|
|
||||||
self.update(**kwargs)
|
self.update(**kwargs)
|
||||||
|
@ -15,7 +15,7 @@ from mitmproxy import http
|
|||||||
def test_configure():
|
def test_configure():
|
||||||
d = dumper.Dumper()
|
d = dumper.Dumper()
|
||||||
with taddons.context(d) as ctx:
|
with taddons.context(d) as ctx:
|
||||||
ctx.configure(d, view_filter="~b foo")
|
ctx.configure(d, dumper_filter="~b foo")
|
||||||
assert d.filter
|
assert d.filter
|
||||||
|
|
||||||
f = tflow.tflow(resp=True)
|
f = tflow.tflow(resp=True)
|
||||||
@ -23,10 +23,10 @@ def test_configure():
|
|||||||
f.response.content = b"foo"
|
f.response.content = b"foo"
|
||||||
assert d.match(f)
|
assert d.match(f)
|
||||||
|
|
||||||
ctx.configure(d, view_filter=None)
|
ctx.configure(d, dumper_filter=None)
|
||||||
assert not d.filter
|
assert not d.filter
|
||||||
with pytest.raises(exceptions.OptionsError):
|
with pytest.raises(exceptions.OptionsError):
|
||||||
ctx.configure(d, view_filter="~~")
|
ctx.configure(d, dumper_filter="~~")
|
||||||
assert not d.filter
|
assert not d.filter
|
||||||
|
|
||||||
|
|
||||||
|
@ -10,13 +10,13 @@ from .. import tservers
|
|||||||
|
|
||||||
|
|
||||||
class TestDumpMaster(tservers.MasterTest):
|
class TestDumpMaster(tservers.MasterTest):
|
||||||
def mkmaster(self, flt, **opts):
|
def mkmaster(self, **opts):
|
||||||
o = options.Options(view_filter=flt, **opts)
|
o = options.Options(**opts)
|
||||||
m = dump.DumpMaster(o, with_termlog=False, with_dumper=False)
|
m = dump.DumpMaster(o, with_termlog=False, with_dumper=False)
|
||||||
return m
|
return m
|
||||||
|
|
||||||
def test_has_error(self):
|
def test_has_error(self):
|
||||||
m = self.mkmaster(None)
|
m = self.mkmaster()
|
||||||
ent = log.LogEntry("foo", "error")
|
ent = log.LogEntry("foo", "error")
|
||||||
ent.reply = controller.DummyReply()
|
ent.reply = controller.DummyReply()
|
||||||
m.addons.trigger("log", ent)
|
m.addons.trigger("log", ent)
|
||||||
|
Loading…
Reference in New Issue
Block a user