mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2025-01-30 14:58:38 +00:00
Add GET /options RESTful API for mitmweb.
This commit is contained in:
parent
2ceefe9582
commit
aabc78350a
@ -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 {}
|
||||
|
@ -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"),
|
||||
|
Loading…
Reference in New Issue
Block a user