aboutsummaryrefslogtreecommitdiffstats
path: root/libpathod/app.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-04-29 21:15:02 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-04-29 21:15:02 +1200
commit1431b36c4a226dc9b57a3334364a0c40162c388f (patch)
treea2e65e7cecad73c6e579ef63c3358f5baa4afb78 /libpathod/app.py
parent37e880b3990e2729d857b0f3a24f80d45116b7f0 (diff)
downloadmitmproxy-1431b36c4a226dc9b57a3334364a0c40162c388f.tar.gz
mitmproxy-1431b36c4a226dc9b57a3334364a0c40162c388f.tar.bz2
mitmproxy-1431b36c4a226dc9b57a3334364a0c40162c388f.zip
Preview in web application.
Diffstat (limited to 'libpathod/app.py')
-rw-r--r--libpathod/app.py24
1 files changed, 23 insertions, 1 deletions
diff --git a/libpathod/app.py b/libpathod/app.py
index 685ac22e..0274853b 100644
--- a/libpathod/app.py
+++ b/libpathod/app.py
@@ -6,6 +6,7 @@ class _Page(tornado.web.RequestHandler):
def render(self, name, **kwargs):
tornado.web.RequestHandler.render(self, name + ".html", **kwargs)
+
class Index(_Page):
name = "index"
section = "main"
@@ -16,8 +17,29 @@ class Index(_Page):
class Preview(_Page):
name = "preview"
section = "main"
+ SANITY = 1024*1024
def get(self):
- self.render(self.name, section=self.section)
+ spec = self.get_argument("spec", None)
+ args = dict(
+ spec = spec,
+ section = self.section,
+ syntaxerror = None,
+ error = None
+ )
+ try:
+ r = rparse.parse(self.application.settings, spec)
+ except rparse.ParseException, v:
+ args["syntaxerror"] = str(v)
+ args["marked"] = v.marked()
+ return self.render(self.name, **args)
+ if r.length() > self.SANITY:
+ error = "Refusing to preview a response of %s bytes. This is for your own good."%r.length()
+ args["error"] = error
+ else:
+ d = utils.DummyRequest()
+ r.serve(d)
+ args["output"] = d.getvalue()
+ self.render(self.name, **args)
class Help(_Page):