aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-10-01 12:01:02 +1300
committerAldo Cortesi <aldo@nullcube.com>2012-10-01 12:01:02 +1300
commit915bcfbd305d7b18de07f4f40dab1e49a06b132c (patch)
tree1b2e0226e9ad9e3a5ac97d643886faa80740b113
parent8bb81be2b07b4b93a8ec7c088bf1ff4728fcec21 (diff)
downloadmitmproxy-915bcfbd305d7b18de07f4f40dab1e49a06b132c.tar.gz
mitmproxy-915bcfbd305d7b18de07f4f40dab1e49a06b132c.tar.bz2
mitmproxy-915bcfbd305d7b18de07f4f40dab1e49a06b132c.zip
Add timeout argument to Pathod, and matching -t command-line option.
-rw-r--r--libpathod/pathod.py14
-rwxr-xr-xpathod7
-rw-r--r--test/test_pathod.py9
-rw-r--r--test/tutils.py4
4 files changed, 30 insertions, 4 deletions
diff --git a/libpathod/pathod.py b/libpathod/pathod.py
index 1c53d7d7..3cf96206 100644
--- a/libpathod/pathod.py
+++ b/libpathod/pathod.py
@@ -145,7 +145,7 @@ class PathodHandler(tcp.BaseHandler):
)
self.info(s)
return
-
+ self.settimeout(self.server.timeout)
while not self.finished:
if not self.handle_request():
return
@@ -155,7 +155,8 @@ 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, nohang=False
+ sizelimit=None, noweb=False, nocraft=False, noapi=False, nohang=False,
+ timeout=None
):
"""
addr: (address, port) tuple. If port is 0, a free port will be
@@ -175,6 +176,7 @@ class Pathod(tcp.TCPServer):
self.craftanchor = craftanchor
self.sizelimit = sizelimit
self.noweb, self.nocraft, self.noapi, self.nohang = noweb, nocraft, noapi, nohang
+ self.timeout = timeout
if not noapi:
app.api()
self.app = app.app
@@ -224,6 +226,14 @@ class Pathod(tcp.TCPServer):
)
)
return
+ except tcp.NetLibTimeout: # pragma: no cover
+ h.info("Timeout")
+ self.add_log(
+ dict(
+ type = "timeout",
+ )
+ )
+ return
def add_log(self, d):
if not self.noapi:
diff --git a/pathod b/pathod
index 82a7edc0..91cd13e3 100755
--- a/pathod
+++ b/pathod
@@ -88,7 +88,8 @@ def main(parser, args):
noweb = args.noweb,
nocraft = args.nocraft,
noapi = args.noapi,
- nohang = args.nohang
+ nohang = args.nohang,
+ timeout = args.timeout
)
except pathod.PathodError, v:
parser.error(str(v))
@@ -135,6 +136,10 @@ if __name__ == "__main__":
help='Serve with SSL.'
)
parser.add_argument(
+ "-t", dest="timeout", type=int, default=None,
+ help="Connection timeout"
+ )
+ parser.add_argument(
"--limit-size", dest='sizelimit', default=None, type=str,
help='Size limit of served responses. Understands size suffixes, i.e. 100k.'
)
diff --git a/test/test_pathod.py b/test/test_pathod.py
index 9c205d4f..429c2ef9 100644
--- a/test/test_pathod.py
+++ b/test/test_pathod.py
@@ -34,6 +34,15 @@ class TestNoWeb(tutils.DaemonTests):
assert self.getpath("/").status_code == 800
+class TestTimeout(tutils.DaemonTests):
+ timeout = 0.1
+ def test_noweb(self):
+ # FIXME: Add float values to spec language, reduce test timeout to
+ # increase test performance
+ assert self.get("200:p1,1").status_code == 200
+ assert self.d.last_log()["type"] == "timeout"
+
+
class TestNoApi(tutils.DaemonTests):
noapi = True
def test_noapi(self):
diff --git a/test/tutils.py b/test/tutils.py
index 60f2ffc0..8e7bca20 100644
--- a/test/tutils.py
+++ b/test/tutils.py
@@ -8,6 +8,7 @@ class DaemonTests:
noapi = False
nohang = False
ssl = False
+ timeout = None
@classmethod
def setUpAll(self):
self.d = test.Daemon(
@@ -17,7 +18,8 @@ class DaemonTests:
sizelimit=1*1024*1024,
noweb = self.noweb,
noapi = self.noapi,
- nohang = self.nohang
+ nohang = self.nohang,
+ timeout = self.timeout,
)
@classmethod