From 38d926d159221d7e4a4bd2c895a040f351f5264f Mon Sep 17 00:00:00 2001 From: Matthew Shao Date: Mon, 24 Jul 2017 20:32:46 +0800 Subject: [PATCH] [web] Add /options/dump API to backend. --- mitmproxy/tools/web/app.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/mitmproxy/tools/web/app.py b/mitmproxy/tools/web/app.py index c6fb2ef64..36cb1ca1e 100644 --- a/mitmproxy/tools/web/app.py +++ b/mitmproxy/tools/web/app.py @@ -451,6 +451,22 @@ class Options(RequestHandler): raise APIError(400, "{}".format(err)) +class DumpOptions(RequestHandler): + def get(self): + self.set_header("Content-Disposition", "attachment; filename=options") + self.set_header("Content-Type", "application/octet-stream") + + data = optmanager.save(self.master.options) + self.write(data) + + def post(self): + try: + data = optmanager.parse(self.filecontents) + self.master.options.update(**data) + except Exception as err: + raise APIError(400, "{}".format(err)) + + class Application(tornado.web.Application): def __init__(self, master, debug): self.master = master @@ -475,7 +491,8 @@ class Application(tornado.web.Application): FlowContentView), (r"/settings", Settings), (r"/clear", ClearAll), - (r"/options", Options) + (r"/options", Options), + (r"/options/dump", DumpOptions) ] settings = dict( template_path=os.path.join(os.path.dirname(__file__), "templates"),