[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 version
from mitmproxy import optmanager
from mitmproxy import options
from mitmproxy.tools.cmdline import CONFIG_PATH
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:
"""
@ -454,10 +452,10 @@ class Options(RequestHandler):
raise APIError(400, "{}".format(err))
class DumpOptions(RequestHandler):
class SaveOptions(RequestHandler):
def post(self):
try:
optmanager.save(self.master.options, CONFIG_PATH)
optmanager.save(self.master.options, CONFIG_PATH, True)
except Exception as err:
raise APIError(400, "{}".format(err))
@ -487,7 +485,7 @@ class Application(tornado.web.Application):
(r"/settings", Settings),
(r"/clear", ClearAll),
(r"/options", Options),
(r"/options/dump", DumpOptions)
(r"/options/save", SaveOptions)
]
settings = dict(
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),
"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:
iol.start()
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", {"anticache": "foo"}).code == 400
def test_option_dump(self):
assert self.fetch("/options/dump", method="POST").code == 200
def test_option_save(self):
assert self.fetch("/options/save", method="POST").code == 200
def test_err(self):
with mock.patch("mitmproxy.tools.web.app.IndexHandler.get") as f: