aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mitmproxy/addonmanager.py4
-rw-r--r--mitmproxy/addons/view.py27
-rw-r--r--mitmproxy/options.py60
-rw-r--r--mitmproxy/test/taddons.py2
-rw-r--r--mitmproxy/tools/cmdline.py2
-rw-r--r--mitmproxy/tools/console/consoleaddons.py48
-rw-r--r--mitmproxy/tools/console/eventlog.py6
-rw-r--r--mitmproxy/tools/console/statusbar.py6
-rw-r--r--test/mitmproxy/addons/test_view.py15
-rw-r--r--test/mitmproxy/test_addonmanager.py2
-rw-r--r--test/mitmproxy/tools/console/test_statusbar.py3
11 files changed, 97 insertions, 78 deletions
diff --git a/mitmproxy/addonmanager.py b/mitmproxy/addonmanager.py
index 857ed530..31665548 100644
--- a/mitmproxy/addonmanager.py
+++ b/mitmproxy/addonmanager.py
@@ -202,6 +202,10 @@ class AddonManager:
def __str__(self):
return pprint.pformat([str(i) for i in self.chain])
+ def __contains__(self, item):
+ name = _get_name(item)
+ return name in self.lookup
+
def handle_lifecycle(self, name, message):
"""
Handle a lifecycle event.
diff --git a/mitmproxy/addons/view.py b/mitmproxy/addons/view.py
index b2db0171..8ae1f341 100644
--- a/mitmproxy/addons/view.py
+++ b/mitmproxy/addons/view.py
@@ -145,6 +145,21 @@ class View(collections.Sequence):
self.focus = Focus(self)
self.settings = Settings(self)
+ def load(self, loader):
+ loader.add_option(
+ "view_order", str, "time",
+ "Flow sort order.",
+ choices=list(map(lambda c: c[1], orders)),
+ )
+ loader.add_option(
+ "view_order_reversed", bool, False,
+ "Reverse the sorting order."
+ )
+ loader.add_option(
+ "console_focus_follow", bool, False,
+ "Focus follows new flows."
+ )
+
def store_count(self):
return len(self._store)
@@ -442,14 +457,14 @@ class View(collections.Sequence):
"Invalid interception filter: %s" % ctx.options.view_filter
)
self.set_filter(filt)
- if "console_order" in updated:
- if ctx.options.console_order not in self.orders:
+ if "view_order" in updated:
+ if ctx.options.view_order not in self.orders:
raise exceptions.OptionsError(
- "Unknown flow order: %s" % ctx.options.console_order
+ "Unknown flow order: %s" % ctx.options.view_order
)
- self.set_order(self.orders[ctx.options.console_order])
- if "console_order_reversed" in updated:
- self.set_reversed(ctx.options.console_order_reversed)
+ self.set_order(self.orders[ctx.options.view_order])
+ if "view_order_reversed" in updated:
+ self.set_reversed(ctx.options.view_order_reversed)
if "console_focus_follow" in updated:
self.focus_follow = ctx.options.console_focus_follow
diff --git a/mitmproxy/options.py b/mitmproxy/options.py
index 1ecdd6a6..b008e588 100644
--- a/mitmproxy/options.py
+++ b/mitmproxy/options.py
@@ -4,29 +4,6 @@ from mitmproxy import optmanager
from mitmproxy import contentviews
from mitmproxy.net import tcp
-# We redefine these here for now to avoid importing Urwid-related guff on
-# platforms that don't support it, and circular imports. We can do better using
-# a lazy checker down the track.
-console_palettes = [
- "lowlight",
- "lowdark",
- "light",
- "dark",
- "solarized_light",
- "solarized_dark"
-]
-view_orders = [
- "time",
- "method",
- "url",
- "size",
-]
-console_layouts = [
- "single",
- "vertical",
- "horizontal",
-]
-
log_verbosity = [
"error",
"warn",
@@ -475,43 +452,6 @@ class Options(optmanager.OptManager):
"Intercept filter expression."
)
- # Console options
- self.add_option(
- "console_layout", str, "single",
- "Console layout.",
- choices=sorted(console_layouts),
- )
- self.add_option(
- "console_layout_headers", bool, True,
- "Show layout comonent headers",
- )
- self.add_option(
- "console_focus_follow", bool, False,
- "Focus follows new flows."
- )
- self.add_option(
- "console_palette", str, "solarized_dark",
- "Color palette.",
- choices=sorted(console_palettes),
- )
- self.add_option(
- "console_palette_transparent", bool, False,
- "Set transparent background for palette."
- )
- self.add_option(
- "console_mouse", bool, True,
- "Console mouse interaction."
- )
- self.add_option(
- "console_order", str, "time",
- "Flow sort order.",
- choices=view_orders,
- )
- self.add_option(
- "console_order_reversed", bool, False,
- "Reverse the sorting order."
- )
-
self.add_option(
"view_filter", Optional[str], None,
"Limit which flows are displayed."
diff --git a/mitmproxy/test/taddons.py b/mitmproxy/test/taddons.py
index 6160746a..d966f1d5 100644
--- a/mitmproxy/test/taddons.py
+++ b/mitmproxy/test/taddons.py
@@ -105,6 +105,8 @@ class context:
Options object with the given keyword arguments, then calls the
configure method on the addon with the updated value.
"""
+ if addon not in self.master.addons:
+ self.master.addons.register(addon)
with self.options.rollback(kwargs.keys(), reraise=True):
self.options.update(**kwargs)
self.master.addons.invoke_addon(
diff --git a/mitmproxy/tools/cmdline.py b/mitmproxy/tools/cmdline.py
index 93ce6f24..d611a8d2 100644
--- a/mitmproxy/tools/cmdline.py
+++ b/mitmproxy/tools/cmdline.py
@@ -48,7 +48,7 @@ def common_options(parser, opts):
)
parser.add_argument(
"-v", "--verbose",
- action="store_const", dest="verbose", const=3,
+ action="store_const", dest="verbose", const='debug',
help="Increase log verbosity."
)
diff --git a/mitmproxy/tools/console/consoleaddons.py b/mitmproxy/tools/console/consoleaddons.py
index 853447cf..49934e4d 100644
--- a/mitmproxy/tools/console/consoleaddons.py
+++ b/mitmproxy/tools/console/consoleaddons.py
@@ -11,6 +11,26 @@ from mitmproxy.tools.console import overlay
from mitmproxy.tools.console import signals
from mitmproxy.tools.console import keymap
+console_palettes = [
+ "lowlight",
+ "lowdark",
+ "light",
+ "dark",
+ "solarized_light",
+ "solarized_dark"
+]
+view_orders = [
+ "time",
+ "method",
+ "url",
+ "size",
+]
+console_layouts = [
+ "single",
+ "vertical",
+ "horizontal",
+]
+
class Logger:
def log(self, evt):
@@ -60,6 +80,34 @@ class ConsoleAddon:
self.master = master
self.started = False
+ def load(self, loader):
+ loader.add_option(
+ "console_layout", str, "single",
+ "Console layout.",
+ choices=sorted(console_layouts),
+ )
+ loader.add_option(
+ "console_layout_headers", bool, True,
+ "Show layout comonent headers",
+ )
+ loader.add_option(
+ "console_focus_follow", bool, False,
+ "Focus follows new flows."
+ )
+ loader.add_option(
+ "console_palette", str, "solarized_dark",
+ "Color palette.",
+ choices=sorted(console_palettes),
+ )
+ loader.add_option(
+ "console_palette_transparent", bool, False,
+ "Set transparent background for palette."
+ )
+ loader.add_option(
+ "console_mouse", bool, True,
+ "Console mouse interaction."
+ )
+
@command.command("console.layout.options")
def layout_options(self) -> typing.Sequence[str]:
"""
diff --git a/mitmproxy/tools/console/eventlog.py b/mitmproxy/tools/console/eventlog.py
index a76b910e..c3e5dd39 100644
--- a/mitmproxy/tools/console/eventlog.py
+++ b/mitmproxy/tools/console/eventlog.py
@@ -22,6 +22,12 @@ class EventLog(urwid.ListBox, layoutwidget.LayoutWidget):
signals.sig_add_log.connect(self.sig_add_log)
signals.sig_clear_log.connect(self.sig_clear_log)
+ def load(self, loader):
+ loader.add_option(
+ "console_focus_follow", bool, False,
+ "Focus follows new flows."
+ )
+
def set_focus(self, index):
if 0 <= index < len(self.walker):
super().set_focus(index)
diff --git a/mitmproxy/tools/console/statusbar.py b/mitmproxy/tools/console/statusbar.py
index 5bfc611c..795b3d8a 100644
--- a/mitmproxy/tools/console/statusbar.py
+++ b/mitmproxy/tools/console/statusbar.py
@@ -199,10 +199,10 @@ class StatusBar(urwid.WidgetWrap):
r.append("[")
r.append(("heading_key", "M"))
r.append(":%s]" % self.master.options.default_contentview)
- if self.master.options.has_changed("console_order"):
+ if self.master.options.has_changed("view_order"):
r.append("[")
r.append(("heading_key", "o"))
- r.append(":%s]" % self.master.options.console_order)
+ r.append(":%s]" % self.master.options.view_order)
opts = []
if self.master.options.anticache:
@@ -244,7 +244,7 @@ class StatusBar(urwid.WidgetWrap):
else:
offset = self.master.view.focus.index + 1
- if self.master.options.console_order_reversed:
+ if self.master.options.view_order_reversed:
arrow = common.SYMBOL_UP
else:
arrow = common.SYMBOL_DOWN
diff --git a/test/mitmproxy/addons/test_view.py b/test/mitmproxy/addons/test_view.py
index e8eeb591..1e0c3b55 100644
--- a/test/mitmproxy/addons/test_view.py
+++ b/test/mitmproxy/addons/test_view.py
@@ -7,6 +7,7 @@ from mitmproxy import flowfilter
from mitmproxy import exceptions
from mitmproxy import io
from mitmproxy.test import taddons
+from mitmproxy.tools.console import consoleaddons
def tft(*, method="get", start=0):
@@ -27,7 +28,7 @@ def test_order_refresh():
tf = tflow.tflow(resp=True)
with taddons.context() as tctx:
- tctx.configure(v, console_order="time")
+ tctx.configure(v, view_order="time")
v.add([tf])
tf.request.timestamp_start = 1
assert not sargs
@@ -300,12 +301,12 @@ def test_order():
v.request(tft(method="put", start=4))
assert [i.request.timestamp_start for i in v] == [1, 2, 3, 4]
- tctx.configure(v, console_order="method")
+ tctx.configure(v, view_order="method")
assert [i.request.method for i in v] == ["GET", "GET", "PUT", "PUT"]
v.set_reversed(True)
assert [i.request.method for i in v] == ["PUT", "PUT", "GET", "GET"]
- tctx.configure(v, console_order="time")
+ tctx.configure(v, view_order="time")
assert [i.request.timestamp_start for i in v] == [4, 3, 2, 1]
v.set_reversed(False)
@@ -425,6 +426,8 @@ def test_signals():
def test_focus_follow():
v = view.View()
with taddons.context() as tctx:
+ console_addon = consoleaddons.ConsoleAddon(tctx.master)
+ tctx.configure(console_addon)
tctx.configure(v, console_focus_follow=True, view_filter="~m get")
v.add([tft(start=5)])
@@ -546,11 +549,11 @@ def test_configure():
with pytest.raises(Exception, match="Invalid interception filter"):
tctx.configure(v, view_filter="~~")
- tctx.configure(v, console_order="method")
+ tctx.configure(v, view_order="method")
with pytest.raises(Exception, match="Unknown flow order"):
- tctx.configure(v, console_order="no")
+ tctx.configure(v, view_order="no")
- tctx.configure(v, console_order_reversed=True)
+ tctx.configure(v, view_order_reversed=True)
tctx.configure(v, console_focus_follow=True)
assert v.focus_follow
diff --git a/test/mitmproxy/test_addonmanager.py b/test/mitmproxy/test_addonmanager.py
index accf48e0..274d2d90 100644
--- a/test/mitmproxy/test_addonmanager.py
+++ b/test/mitmproxy/test_addonmanager.py
@@ -137,6 +137,8 @@ def test_simple():
a.trigger("custom")
assert ta.custom_called
+ assert ta in a
+
def test_load_option():
o = options.Options()
diff --git a/test/mitmproxy/tools/console/test_statusbar.py b/test/mitmproxy/tools/console/test_statusbar.py
index 2f7825c9..b131a5d3 100644
--- a/test/mitmproxy/tools/console/test_statusbar.py
+++ b/test/mitmproxy/tools/console/test_statusbar.py
@@ -13,20 +13,19 @@ def test_statusbar(monkeypatch):
stickycookie="~dst example.com",
stickyauth="~dst example.com",
default_contentview="javascript",
- console_order="url",
anticache=True,
anticomp=True,
showhost=True,
refresh_server_playback=False,
replay_kill_extra=True,
upstream_cert=False,
- console_focus_follow=True,
stream_large_bodies="3m",
mode="transparent",
scripts=["nonexistent"],
save_stream_file="foo",
)
m = master.ConsoleMaster(o)
+ m.options.update(view_order='url', console_focus_follow=True)
monkeypatch.setattr(m.addons.get("clientplayback"), "count", lambda: 42)
monkeypatch.setattr(m.addons.get("serverplayback"), "count", lambda: 42)