aboutsummaryrefslogtreecommitdiffstats
path: root/libpathod/app.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-07-25 00:16:24 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-07-25 00:18:23 +1200
commit7dab85e8b1de9101cadcc75768672a7ca26da3b8 (patch)
tree1ad6a3ca113a8eda045f4b3c1806ae4fead7d899 /libpathod/app.py
parent64ef0a4561058de4ca7309767e89366bc1c7502f (diff)
downloadmitmproxy-7dab85e8b1de9101cadcc75768672a7ca26da3b8.tar.gz
mitmproxy-7dab85e8b1de9101cadcc75768672a7ca26da3b8.tar.bz2
mitmproxy-7dab85e8b1de9101cadcc75768672a7ca26da3b8.zip
Handle file access denied errors in previews.
Diffstat (limited to 'libpathod/app.py')
-rw-r--r--libpathod/app.py51
1 files changed, 27 insertions, 24 deletions
diff --git a/libpathod/app.py b/libpathod/app.py
index 79c0fc71..cf66f8d4 100644
--- a/libpathod/app.py
+++ b/libpathod/app.py
@@ -75,8 +75,12 @@ def onelog(lid):
return render("onelog.html", section="log", alog=l, lid=lid)
-@app.route('/response_preview')
-def response_preview():
+def _preview(is_request):
+ if is_request:
+ template = "request_preview.html"
+ else:
+ template = "response_preview.html"
+
spec = request.args["spec"]
args = dict(
spec = spec,
@@ -85,37 +89,36 @@ def response_preview():
error = None
)
try:
- r = rparse.parse_response(app.config["pathod"].request_settings, spec)
+ if is_request:
+ r = rparse.parse_request(app.config["pathod"].request_settings, spec)
+ else:
+ r = rparse.parse_response(app.config["pathod"].request_settings, spec)
except rparse.ParseException, v:
args["syntaxerror"] = str(v)
args["marked"] = v.marked()
- return render("response_preview.html", **args)
+ return render(template, **args)
+ except rparse.FileAccessDenied:
+ args["error"] = "File access is disabled."
+ return render(template, **args)
s = cStringIO.StringIO()
r.preview_safe()
- r.serve(s, check=app.config["pathod"].check_size)
+
+ if is_request:
+ r.serve(s, check=app.config["pathod"].check_size, host="example.com")
+ else:
+ r.serve(s, check=app.config["pathod"].check_size)
+
args["output"] = utils.escape_unprintables(s.getvalue())
- return render("response_preview.html", **args)
+ return render(template, **args)
+@app.route('/response_preview')
+def response_preview():
+ return _preview(False)
+
+
@app.route('/request_preview')
def request_preview():
- spec = request.args["spec"]
- args = dict(
- spec = spec,
- section = "main",
- syntaxerror = None,
- error = None
- )
- try:
- r = rparse.parse_request(app.config["pathod"].request_settings, spec)
- except rparse.ParseException, v:
- args["syntaxerror"] = str(v)
- args["marked"] = v.marked()
- return render("request_preview.html", **args)
+ return _preview(True)
- s = cStringIO.StringIO()
- r.preview_safe()
- r.serve(s, check=app.config["pathod"].check_size, host="example.com")
- args["output"] = utils.escape_unprintables(s.getvalue())
- return render("request_preview.html", **args)