mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-27 02:24:18 +00:00
Add preview for pathoc requests to web app.
This commit is contained in:
parent
6c565e778f
commit
ab59d6dccf
@ -73,8 +73,8 @@ def onelog(lid):
|
|||||||
return render("onelog.html", section="log", alog=l, lid=lid)
|
return render("onelog.html", section="log", alog=l, lid=lid)
|
||||||
|
|
||||||
|
|
||||||
@app.route('/preview')
|
@app.route('/response_preview')
|
||||||
def preview():
|
def response_preview():
|
||||||
spec = request.args["spec"]
|
spec = request.args["spec"]
|
||||||
args = dict(
|
args = dict(
|
||||||
spec = spec,
|
spec = spec,
|
||||||
@ -87,10 +87,33 @@ def preview():
|
|||||||
except rparse.ParseException, v:
|
except rparse.ParseException, v:
|
||||||
args["syntaxerror"] = str(v)
|
args["syntaxerror"] = str(v)
|
||||||
args["marked"] = v.marked()
|
args["marked"] = v.marked()
|
||||||
return render("preview.html", **args)
|
return render("preview_response.html", **args)
|
||||||
|
|
||||||
s = cStringIO.StringIO()
|
s = cStringIO.StringIO()
|
||||||
r.preview_safe()
|
r.preview_safe()
|
||||||
r.serve(s, check=app.config["pathod"].check_size)
|
r.serve(s, check=app.config["pathod"].check_size)
|
||||||
args["output"] = utils.escape_unprintables(s.getvalue())
|
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)
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
|
|
||||||
|
|
||||||
section {
|
section {
|
||||||
margin-top: 50px;
|
margin-top: 50px;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.example {
|
.example {
|
||||||
margin-top: 10px;
|
margin-top: 10px;
|
||||||
margin-bottom: 10px;
|
margin-bottom: 10px;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.terminal {
|
.terminal {
|
||||||
|
@ -1,29 +1,33 @@
|
|||||||
{% extends "frame.html" %}
|
{% extends "frame.html" %}
|
||||||
{% block body %}
|
{% block body %}
|
||||||
{% include "previewform.html" %}
|
|
||||||
|
|
||||||
<div class="hero-unit">
|
<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>
|
||||||
|
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="span4">
|
<div class="span6">
|
||||||
<div class="well">
|
<div class="well">
|
||||||
<h1> <a href="/docs/pathod">pathod</a> </h1>
|
<h1> <a href="/docs/pathod">pathod</a> </h1>
|
||||||
|
|
||||||
A pathological web daemon.
|
A pathological web daemon.
|
||||||
|
|
||||||
|
{% include "response_previewform.html" %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="span4">
|
<div class="span6">
|
||||||
<div class="well">
|
<div class="well">
|
||||||
<h1> <a href="/docs/pathoc">pathoc</a> </h1>
|
<h1> <a href="/docs/pathoc">pathoc</a> </h1>
|
||||||
|
|
||||||
A perverse HTTP client.
|
A perverse HTTP client.
|
||||||
|
|
||||||
|
{% include "request_previewform.html" %}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="span4">
|
</div>
|
||||||
|
|
||||||
|
<div class="row">
|
||||||
|
<div class="span12">
|
||||||
<div class="well">
|
<div class="well">
|
||||||
<h1> <a href="/docs/test">libpathod.test</a> </h1>
|
<h1> <a href="/docs/test">libpathod.test</a> </h1>
|
||||||
|
|
||||||
@ -33,5 +37,4 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
23
libpathod/templates/preview_request.html
Normal file
23
libpathod/templates/preview_request.html
Normal file
@ -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 %}
|
@ -19,5 +19,5 @@
|
|||||||
<pre>{{ output }}</pre>
|
<pre>{{ output }}</pre>
|
||||||
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% include "previewform.html" %}
|
{% include "response_previewform.html" %}
|
||||||
{% endblock %}
|
{% endblock %}
|
4
libpathod/templates/request_previewform.html
Normal file
4
libpathod/templates/request_previewform.html
Normal file
@ -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>
|
@ -1,5 +1,5 @@
|
|||||||
<form class="well form-search" method="GET" action="/preview">
|
<form class="form-inline" method="GET" action="/response_preview">
|
||||||
<input id="spec" style="width: 30em;" name="spec" class="input-medium search-query" value="{{spec}}">
|
<input id="spec" name="spec" class="input-medium search-query" value="{{spec}}">
|
||||||
<input type="submit" class="btn" value="preview">
|
<input type="submit" class="btn" value="preview">
|
||||||
<a href="#" id="submitspec" class="btn">go</a>
|
<a href="#" id="submitspec" class="btn">go</a>
|
||||||
</form>
|
</form>
|
@ -21,21 +21,40 @@ class TestApp(tutils.DaemonTests):
|
|||||||
assert self.getpath("/log/%s"%id).status_code == 200
|
assert self.getpath("/log/%s"%id).status_code == 200
|
||||||
assert self.getpath("/log/9999999").status_code == 404
|
assert self.getpath("/log/9999999").status_code == 404
|
||||||
|
|
||||||
def test_preview(self):
|
def test_response_preview(self):
|
||||||
r = self.getpath("/preview", params=dict(spec="200"))
|
r = self.getpath("/response_preview", params=dict(spec="200"))
|
||||||
assert r.status_code == 200
|
assert r.status_code == 200
|
||||||
assert 'Response' in r.content
|
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 r.status_code == 200
|
||||||
assert 'Error' in r.content
|
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 r.status_code == 200
|
||||||
assert "too large" in r.content
|
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 r.status_code == 200
|
||||||
assert 'Response' in r.content
|
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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user