[web] Update POST /options/dump API in backend.

This commit is contained in:
Matthew Shao 2017-07-26 15:06:42 +08:00
parent 5c45a90ce9
commit 9d16cc7079

View File

@ -18,8 +18,10 @@ from mitmproxy import io
from mitmproxy import log from mitmproxy import log
from mitmproxy import version from mitmproxy import version
from mitmproxy import optmanager from mitmproxy import optmanager
from mitmproxy import options
import mitmproxy.tools.web.master # noqa import mitmproxy.tools.web.master # noqa
CONFIG_PATH = os.path.expanduser(os.path.join(options.CA_DIR, 'config.yaml'))
def flow_to_json(flow: mitmproxy.flow.Flow) -> dict: def flow_to_json(flow: mitmproxy.flow.Flow) -> dict:
""" """
@ -452,17 +454,9 @@ class Options(RequestHandler):
class DumpOptions(RequestHandler): 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): def post(self):
try: try:
data = optmanager.parse(self.filecontents) optmanager.save(self.master.options, CONFIG_PATH)
self.master.options.update(**data)
except Exception as err: except Exception as err:
raise APIError(400, "{}".format(err)) raise APIError(400, "{}".format(err))