aboutsummaryrefslogtreecommitdiffstats
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
parentb879890412041e7364a294151a3a8aef5fb62e48 (diff)
downloadmitmproxy-3e158211a830bbcba2dd463189a79ec3ad17c8d4.tar.gz
mitmproxy-3e158211a830bbcba2dd463189a79ec3ad17c8d4.tar.bz2
mitmproxy-3e158211a830bbcba2dd463189a79ec3ad17c8d4.zip
Add a --nohang flag that turns off pauses in response generation.
-rw-r--r--libpathod/app.py4
-rw-r--r--libpathod/pathod.py15
-rwxr-xr-xpathod7
-rw-r--r--test/test_pathod.py9
-rw-r--r--test/tutils.py4
5 files changed, 30 insertions, 9 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
diff --git a/pathod b/pathod
index df044ae7..56f6e3fe 100755
--- a/pathod
+++ b/pathod
@@ -35,6 +35,10 @@ if __name__ == "__main__":
help='Disable API.'
)
parser.add_argument(
+ "--nohang", dest='nohang', default=False, action="store_true",
+ help='Disable pauses during crafted response generation.'
+ )
+ parser.add_argument(
"--noweb", dest='noweb', default=False, action="store_true",
help='Disable both web interface and API.'
)
@@ -100,7 +104,8 @@ if __name__ == "__main__":
sizelimit = sizelimit,
noweb = args.noweb,
nocraft = args.nocraft,
- noapi = args.noapi
+ noapi = args.noapi,
+ nohang = args.nohang
)
except pathod.PathodError, v:
parser.error(str(v))
diff --git a/test/test_pathod.py b/test/test_pathod.py
index 036fbf0b..d6e2e886 100644
--- a/test/test_pathod.py
+++ b/test/test_pathod.py
@@ -43,6 +43,15 @@ class TestNoApi(tutils.DaemonTests):
assert not "Log" in r.content
+class TestNohang(tutils.DaemonTests):
+ nohang = True
+ def test_nohang(self):
+ r = self.get("200:p0,0")
+ assert r.status_code == 800
+ l = self.d.log()[0]
+ assert "Pauses have been disabled" in l["response"]["error"]
+
+
class CommonTests(tutils.DaemonTests):
def test_sizelimit(self):
r = self.get("200:b@1g")
diff --git a/test/tutils.py b/test/tutils.py
index 1eb78980..d9e543a1 100644
--- a/test/tutils.py
+++ b/test/tutils.py
@@ -6,6 +6,7 @@ import requests
class DaemonTests:
noweb = False
noapi = False
+ nohang = False
ssl = False
@classmethod
def setUpAll(self):
@@ -15,7 +16,8 @@ class DaemonTests:
ssl = self.ssl,
sizelimit=1*1024*1024,
noweb = self.noweb,
- noapi = self.noapi
+ noapi = self.noapi,
+ nohang = self.nohang
)
@classmethod