aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libpathod/app.py51
-rw-r--r--libpathod/templates/frame.html2
-rw-r--r--test/test_app.py4
3 files changed, 32 insertions, 25 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)
diff --git a/libpathod/templates/frame.html b/libpathod/templates/frame.html
index 416f3eca..d91004e4 100644
--- a/libpathod/templates/frame.html
+++ b/libpathod/templates/frame.html
@@ -77,7 +77,7 @@
$.localScroll(
{
duration: 300,
- offset: {top: -100}
+ offset: {top: -45}
}
);
});
diff --git a/test/test_app.py b/test/test_app.py
index b0d730af..8070996f 100644
--- a/test/test_app.py
+++ b/test/test_app.py
@@ -38,6 +38,10 @@ class TestApp(tutils.DaemonTests):
assert r.status_code == 200
assert 'Response' in r.content
+ r = self.getpath("/response_preview", params=dict(spec="200:b<foo"))
+ assert r.status_code == 200
+ assert 'File access is disabled' in r.content
+
def test_request_preview(self):
r = self.getpath("/request_preview", params=dict(spec="get:/"))
assert r.status_code == 200