aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--mitmproxy/optmanager.py19
-rw-r--r--test/mitmproxy/tools/web/test_app.py5
2 files changed, 22 insertions, 2 deletions
diff --git a/mitmproxy/optmanager.py b/mitmproxy/optmanager.py
index 3685c003..b67949e0 100644
--- a/mitmproxy/optmanager.py
+++ b/mitmproxy/optmanager.py
@@ -420,12 +420,27 @@ def dump_dicts(opts):
"""
Dumps the options into a list of dict object.
- Return: A list like: [ { name: "anticahce", type: "bool", default: false, value: true, help: "help text"}]
+ Return: A list like: [ { name: "anticache", type: "bool", default: false, value: true, help: "help text"} ]
"""
options_list = []
for k in sorted(opts.keys()):
o = opts._options[k]
- option = {'name': k, 'type': o.typespec.__name__, 'default': o.default, 'value': o.current(), 'help': o.help.strip()}
+ if o.typespec in (str, int, bool):
+ t = o.typespec.__name__
+ elif o.typespec == typing.Optional[str]:
+ t = 'Union'
+ elif o.typespec == typing.Sequence[str]:
+ t = 'Sequence'
+ else:
+ raise NotImplementedError
+ option = {
+ 'name': k,
+ 'type': t,
+ 'default': o.default,
+ 'value': o.current(),
+ 'help': o.help,
+ 'choices': o.choices
+ }
options_list.append(option)
return options_list
diff --git a/test/mitmproxy/tools/web/test_app.py b/test/mitmproxy/tools/web/test_app.py
index 5427b995..d47b1af0 100644
--- a/test/mitmproxy/tools/web/test_app.py
+++ b/test/mitmproxy/tools/web/test_app.py
@@ -253,6 +253,11 @@ class TestApp(tornado.testing.AsyncHTTPTestCase):
assert self.put_json("/settings", {"anticache": True}).code == 200
assert self.put_json("/settings", {"wtf": True}).code == 400
+ def test_options(self):
+ j = json(self.fetch("/options"))
+ assert type(j) == list
+ assert type(j[0]) == dict
+
def test_err(self):
with mock.patch("mitmproxy.tools.web.app.IndexHandler.get") as f:
f.side_effect = RuntimeError