diff options
author | Matthew Shao <me@matshao.com> | 2017-06-12 20:26:46 +0800 |
---|---|---|
committer | Matthew Shao <me@matshao.com> | 2017-06-12 20:26:46 +0800 |
commit | aabc78350a73534729611a6b9bf38fb7e4b390ae (patch) | |
tree | 795e2d5a473ea87f1a6162cf1e878401ea808aa8 | |
parent | 2ceefe9582bd72778648d4f5a154e4d492716b80 (diff) | |
download | mitmproxy-aabc78350a73534729611a6b9bf38fb7e4b390ae.tar.gz mitmproxy-aabc78350a73534729611a6b9bf38fb7e4b390ae.tar.bz2 mitmproxy-aabc78350a73534729611a6b9bf38fb7e4b390ae.zip |
Add GET /options RESTful API for mitmweb.
-rw-r--r-- | mitmproxy/optmanager.py | 14 | ||||
-rw-r--r-- | mitmproxy/tools/web/app.py | 8 |
2 files changed, 22 insertions, 0 deletions
diff --git a/mitmproxy/optmanager.py b/mitmproxy/optmanager.py index 70f60bb6..3685c003 100644 --- a/mitmproxy/optmanager.py +++ b/mitmproxy/optmanager.py @@ -416,6 +416,20 @@ def dump_defaults(opts): return ruamel.yaml.round_trip_dump(s) +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"}] + """ + 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()} + options_list.append(option) + return options_list + + def parse(text): if not text: return {} diff --git a/mitmproxy/tools/web/app.py b/mitmproxy/tools/web/app.py index c55c0cb5..b512671c 100644 --- a/mitmproxy/tools/web/app.py +++ b/mitmproxy/tools/web/app.py @@ -17,6 +17,8 @@ from mitmproxy import http from mitmproxy import io from mitmproxy import log from mitmproxy import version +from mitmproxy import options +from mitmproxy import optmanager import mitmproxy.tools.web.master # noqa @@ -438,6 +440,11 @@ class Settings(RequestHandler): self.master.options.update(**update) +class Options(RequestHandler): + def get(self): + self.write(optmanager.dump_dicts(self.master.options)) + + class Application(tornado.web.Application): def __init__(self, master, debug): self.master = master @@ -462,6 +469,7 @@ class Application(tornado.web.Application): FlowContentView), (r"/settings", Settings), (r"/clear", ClearAll), + (r"/options", Options) ] settings = dict( template_path=os.path.join(os.path.dirname(__file__), "templates"), |