Add GET /options RESTful API for mitmweb.

This commit is contained in:
Matthew Shao 2017-06-12 20:26:46 +08:00
parent 2ceefe9582
commit aabc78350a
2 changed files with 22 additions and 0 deletions

View File

@ -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 {}

View File

@ -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"),