aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libpathod/app.py31
-rw-r--r--libpathod/static/pathod.css3
-rw-r--r--libpathod/templates/index.html15
-rw-r--r--libpathod/templates/preview_request.html23
-rw-r--r--libpathod/templates/preview_response.html (renamed from libpathod/templates/preview.html)2
-rw-r--r--libpathod/templates/request_previewform.html4
-rw-r--r--libpathod/templates/response_previewform.html (renamed from libpathod/templates/previewform.html)4
-rw-r--r--test/test_app.py29
8 files changed, 90 insertions, 21 deletions
diff --git a/libpathod/app.py b/libpathod/app.py
index 111fafe5..6478964c 100644
--- a/libpathod/app.py
+++ b/libpathod/app.py
@@ -73,8 +73,8 @@ def onelog(lid):
return render("onelog.html", section="log", alog=l, lid=lid)
-@app.route('/preview')
-def preview():
+@app.route('/response_preview')
+def response_preview():
spec = request.args["spec"]
args = dict(
spec = spec,
@@ -87,10 +87,33 @@ def preview():
except rparse.ParseException, v:
args["syntaxerror"] = str(v)
args["marked"] = v.marked()
- return render("preview.html", **args)
+ return render("preview_response.html", **args)
s = cStringIO.StringIO()
r.preview_safe()
r.serve(s, check=app.config["pathod"].check_size)
args["output"] = utils.escape_unprintables(s.getvalue())
- return render("preview.html", **args)
+ return render("preview_response.html", **args)
+
+
+@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("preview_request.html", **args)
+
+ 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("preview_request.html", **args)
diff --git a/libpathod/static/pathod.css b/libpathod/static/pathod.css
index 3e24dd7d..ad67179a 100644
--- a/libpathod/static/pathod.css
+++ b/libpathod/static/pathod.css
@@ -1,14 +1,11 @@
-
section {
margin-top: 50px;
-
}
.example {
margin-top: 10px;
margin-bottom: 10px;
-
}
.terminal {
diff --git a/libpathod/templates/index.html b/libpathod/templates/index.html
index 268bc7a5..6702ea2a 100644
--- a/libpathod/templates/index.html
+++ b/libpathod/templates/index.html
@@ -1,29 +1,33 @@
{% extends "frame.html" %}
{% block body %}
-{% include "previewform.html" %}
<div class="hero-unit">
-<h1>Tools for testing and torturing HTTP clients, servers and proxies.</h1>
+<h1>Testing and torturing HTTP clients and servers.</h1>
</div>
<div class="row">
- <div class="span4">
+ <div class="span6">
<div class="well">
<h1> <a href="/docs/pathod">pathod</a> </h1>
A pathological web daemon.
+ {% include "response_previewform.html" %}
</div>
</div>
- <div class="span4">
+ <div class="span6">
<div class="well">
<h1> <a href="/docs/pathoc">pathoc</a> </h1>
A perverse HTTP client.
+ {% include "request_previewform.html" %}
</div>
</div>
- <div class="span4">
+</div>
+
+<div class="row">
+ <div class="span12">
<div class="well">
<h1> <a href="/docs/test">libpathod.test</a> </h1>
@@ -33,5 +37,4 @@
</div>
</div>
-
{% endblock %}
diff --git a/libpathod/templates/preview_request.html b/libpathod/templates/preview_request.html
new file mode 100644
index 00000000..fe8a03e9
--- /dev/null
+++ b/libpathod/templates/preview_request.html
@@ -0,0 +1,23 @@
+{% extends "frame.html" %}
+{% block body %}
+
+<h1>Preview</h1>
+
+{% if syntaxerror %}
+ <h2> Error: {{ syntaxerror }} </h2>
+ <pre>{{ marked }}</pre>
+{% elif error %}
+ <h2> Error </h2>
+ <p style="color: #ff0000">{{ error }}</p>
+{% else %}
+ <h2>Spec:</h2>
+
+ <pre>{{ spec }}</pre>
+
+ <h2>Request:</h2>
+
+ <pre>{{ output }}</pre>
+
+{% endif %}
+{% include "request_previewform.html" %}
+{% endblock %}
diff --git a/libpathod/templates/preview.html b/libpathod/templates/preview_response.html
index 4b5182d7..1b44e480 100644
--- a/libpathod/templates/preview.html
+++ b/libpathod/templates/preview_response.html
@@ -19,5 +19,5 @@
<pre>{{ output }}</pre>
{% endif %}
-{% include "previewform.html" %}
+{% include "response_previewform.html" %}
{% endblock %}
diff --git a/libpathod/templates/request_previewform.html b/libpathod/templates/request_previewform.html
new file mode 100644
index 00000000..accb1631
--- /dev/null
+++ b/libpathod/templates/request_previewform.html
@@ -0,0 +1,4 @@
+<form class="form-inline" method="GET" action="/request_preview">
+ <input id="spec" name="spec" class="input-medium search-query" value="{{spec}}">
+ <input type="submit" class="btn" value="preview">
+</form>
diff --git a/libpathod/templates/previewform.html b/libpathod/templates/response_previewform.html
index 42502ba7..74b25ce1 100644
--- a/libpathod/templates/previewform.html
+++ b/libpathod/templates/response_previewform.html
@@ -1,5 +1,5 @@
-<form class="well form-search" method="GET" action="/preview">
- <input id="spec" style="width: 30em;" name="spec" class="input-medium search-query" value="{{spec}}">
+<form class="form-inline" method="GET" action="/response_preview">
+ <input id="spec" name="spec" class="input-medium search-query" value="{{spec}}">
<input type="submit" class="btn" value="preview">
<a href="#" id="submitspec" class="btn">go</a>
</form>
diff --git a/test/test_app.py b/test/test_app.py
index 0b406ee0..b0d730af 100644
--- a/test/test_app.py
+++ b/test/test_app.py
@@ -21,21 +21,40 @@ class TestApp(tutils.DaemonTests):
assert self.getpath("/log/%s"%id).status_code == 200
assert self.getpath("/log/9999999").status_code == 404
- def test_preview(self):
- r = self.getpath("/preview", params=dict(spec="200"))
+ def test_response_preview(self):
+ r = self.getpath("/response_preview", params=dict(spec="200"))
assert r.status_code == 200
assert 'Response' in r.content
- r = self.getpath("/preview", params=dict(spec="foo"))
+ r = self.getpath("/response_preview", params=dict(spec="foo"))
assert r.status_code == 200
assert 'Error' in r.content
- r = self.getpath("/preview", params=dict(spec="200:b@100m"))
+ r = self.getpath("/response_preview", params=dict(spec="200:b@100m"))
assert r.status_code == 200
assert "too large" in r.content
- r = self.getpath("/preview", params=dict(spec="200:b@5k"))
+ r = self.getpath("/response_preview", params=dict(spec="200:b@5k"))
assert r.status_code == 200
assert 'Response' in r.content
+ def test_request_preview(self):
+ r = self.getpath("/request_preview", params=dict(spec="get:/"))
+ assert r.status_code == 200
+ assert 'Request' in r.content
+
+ r = self.getpath("/request_preview", params=dict(spec="foo"))
+ assert r.status_code == 200
+ assert 'Error' in r.content
+
+ r = self.getpath("/request_preview", params=dict(spec="get:/:b@100m"))
+ assert r.status_code == 200
+ assert "too large" in r.content
+
+ r = self.getpath("/request_preview", params=dict(spec="get:/:b@5k"))
+ assert r.status_code == 200
+ assert 'Request' in r.content
+
+
+