[web] Minor Fix for backend.

This commit is contained in:
Matthew Shao 2017-07-27 11:20:37 +08:00
parent 108ef03585
commit 4ab5574e18
3 changed files with 6 additions and 15 deletions

View File

@ -18,11 +18,9 @@ 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 from mitmproxy.tools.cmdline import CONFIG_PATH
import mitmproxy.tools.web.master # noqa import mitmproxy.tools.web.master # noqa
CONFIG_PATH = 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:
""" """
@ -454,10 +452,10 @@ class Options(RequestHandler):
raise APIError(400, "{}".format(err)) raise APIError(400, "{}".format(err))
class DumpOptions(RequestHandler): class SaveOptions(RequestHandler):
def post(self): def post(self):
try: try:
optmanager.save(self.master.options, CONFIG_PATH) optmanager.save(self.master.options, CONFIG_PATH, True)
except Exception as err: except Exception as err:
raise APIError(400, "{}".format(err)) raise APIError(400, "{}".format(err))
@ -487,7 +485,7 @@ class Application(tornado.web.Application):
(r"/settings", Settings), (r"/settings", Settings),
(r"/clear", ClearAll), (r"/clear", ClearAll),
(r"/options", Options), (r"/options", Options),
(r"/options/dump", DumpOptions) (r"/options/save", SaveOptions)
] ]
settings = dict( settings = dict(
template_path=os.path.join(os.path.dirname(__file__), "templates"), template_path=os.path.join(os.path.dirname(__file__), "templates"),

View File

@ -125,13 +125,6 @@ class WebMaster(master.Master):
"No web browser found. Please open a browser and point it to {}".format(web_url), "No web browser found. Please open a browser and point it to {}".format(web_url),
"info" "info"
) )
unknown_opts = optmanager.load_paths(app.CONFIG_PATH)
if unknown_opts == {}:
self.add_log(
"Load options configuration from {}.".format(app.CONFIG_PATH),
"info"
)
try: try:
iol.start() iol.start()
except KeyboardInterrupt: except KeyboardInterrupt:

View File

@ -263,8 +263,8 @@ class TestApp(tornado.testing.AsyncHTTPTestCase):
assert self.put_json("/options", {"wtf": True}).code == 400 assert self.put_json("/options", {"wtf": True}).code == 400
assert self.put_json("/options", {"anticache": "foo"}).code == 400 assert self.put_json("/options", {"anticache": "foo"}).code == 400
def test_option_dump(self): def test_option_save(self):
assert self.fetch("/options/dump", method="POST").code == 200 assert self.fetch("/options/save", method="POST").code == 200
def test_err(self): def test_err(self):
with mock.patch("mitmproxy.tools.web.app.IndexHandler.get") as f: with mock.patch("mitmproxy.tools.web.app.IndexHandler.get") as f: