aboutsummaryrefslogtreecommitdiffstats
path: root/libpathod
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-07-26 20:01:51 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-07-26 20:01:51 +1200
commit3e158211a830bbcba2dd463189a79ec3ad17c8d4 (patch)
treeb61133ad71a153d77289b408f886de42f79d56b0 /libpathod
parentb879890412041e7364a294151a3a8aef5fb62e48 (diff)
downloadmitmproxy-3e158211a830bbcba2dd463189a79ec3ad17c8d4.tar.gz
mitmproxy-3e158211a830bbcba2dd463189a79ec3ad17c8d4.tar.bz2
mitmproxy-3e158211a830bbcba2dd463189a79ec3ad17c8d4.zip
Add a --nohang flag that turns off pauses in response generation.
Diffstat (limited to 'libpathod')
-rw-r--r--libpathod/app.py4
-rw-r--r--libpathod/pathod.py15
2 files changed, 12 insertions, 7 deletions
diff --git a/libpathod/app.py b/libpathod/app.py
index ebcf0369..29b56711 100644
--- a/libpathod/app.py
+++ b/libpathod/app.py
@@ -117,9 +117,9 @@ def _preview(is_request):
args["pauses"] = r.preview_safe()
if is_request:
- r.serve(s, check=app.config["pathod"].check_size, host="example.com")
+ r.serve(s, check=app.config["pathod"].check_policy, host="example.com")
else:
- r.serve(s, check=app.config["pathod"].check_size)
+ r.serve(s, check=app.config["pathod"].check_policy)
args["output"] = utils.escape_unprintables(s.getvalue())
return render(template, **args)
diff --git a/libpathod/pathod.py b/libpathod/pathod.py
index 8ee7f9ae..b1343ea2 100644
--- a/libpathod/pathod.py
+++ b/libpathod/pathod.py
@@ -19,7 +19,7 @@ class PathodHandler(tcp.BaseHandler):
self.sni = connection.get_servername()
def serve_crafted(self, crafted, request_log):
- response_log = crafted.serve(self.wfile, self.server.check_size)
+ response_log = crafted.serve(self.wfile, self.server.check_policy)
self.server.add_log(
dict(
type = "crafted",
@@ -97,7 +97,7 @@ class PathodHandler(tcp.BaseHandler):
return self.serve_crafted(crafted, request_log)
elif self.server.noweb:
crafted = rparse.PathodErrorResponse("Access Denied")
- crafted.serve(self.wfile, self.server.check_size)
+ crafted.serve(self.wfile, self.server.check_policy)
return False
else:
cc = wsgi.ClientConn(self.client_address)
@@ -150,7 +150,7 @@ class Pathod(tcp.TCPServer):
LOGBUF = 500
def __init__( self,
addr, ssloptions=None, craftanchor="/p/", staticdir=None, anchors=None,
- sizelimit=None, noweb=False, nocraft=False, noapi=False
+ sizelimit=None, noweb=False, nocraft=False, noapi=False, nohang=False
):
"""
addr: (address, port) tuple. If port is 0, a free port will be
@@ -160,13 +160,16 @@ class Pathod(tcp.TCPServer):
staticdir: path to a directory of static resources, or None.
anchors: A list of (regex, spec) tuples, or None.
sizelimit: Limit size of served data.
+ nocraft: Disable response crafting.
+ noapi: Disable the API.
+ nohang: Disable pauses.
"""
tcp.TCPServer.__init__(self, addr)
self.ssloptions = ssloptions
self.staticdir = staticdir
self.craftanchor = craftanchor
self.sizelimit = sizelimit
- self.noweb, self.nocraft, self.noapi = noweb, nocraft, noapi
+ self.noweb, self.nocraft, self.noapi, self.nohang = noweb, nocraft, noapi, nohang
if not noapi:
app.api()
self.app = app.app
@@ -186,12 +189,14 @@ class Pathod(tcp.TCPServer):
raise PathodError("Invalid page spec in anchor: '%s', %s"%(i[1], str(v)))
self.anchors.append((arex, aresp))
- def check_size(self, req, actions):
+ def check_policy(self, req, actions):
"""
A policy check that verifies the request size is withing limits.
"""
if self.sizelimit and req.effective_length(actions) > self.sizelimit:
return "Response too large."
+ if self.nohang and any([i[1] == "pause" for i in actions]):
+ return "Pauses have been disabled."
return False
@property