aboutsummaryrefslogtreecommitdiffstats
path: root/libpathod/pathod.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-06-07 10:17:30 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-06-07 10:17:30 +1200
commitb5a74a26ee6548b493cdece5a05f4fcba71c0012 (patch)
tree6244c184de39e548e38dc63d2f919e0610a02d56 /libpathod/pathod.py
parent049d3d2b45d42245a305bd0bd3b5164a44dc7ba2 (diff)
downloadmitmproxy-b5a74a26ee6548b493cdece5a05f4fcba71c0012.tar.gz
mitmproxy-b5a74a26ee6548b493cdece5a05f4fcba71c0012.tar.bz2
mitmproxy-b5a74a26ee6548b493cdece5a05f4fcba71c0012.zip
Let Pathod pick an arbitrary empty port if -p 0 is specified.
Diffstat (limited to 'libpathod/pathod.py')
-rw-r--r--libpathod/pathod.py19
1 files changed, 16 insertions, 3 deletions
diff --git a/libpathod/pathod.py b/libpathod/pathod.py
index ca24c62c..6b3deaa6 100644
--- a/libpathod/pathod.py
+++ b/libpathod/pathod.py
@@ -205,11 +205,24 @@ class PathodApp(tornado.web.Application):
# begin nocover
-def run(application, port, ssl_options):
+def make_server(application, port, address, ssl_options):
+ """
+ Returns the bound port. This will match the passed port, unless the
+ passed port was 0. In that case, an arbitrary empty port will be bound
+ to, and this new port will be returned.
+ """
http_server = tornado.httpserver.HTTPServer(
application,
ssl_options=ssl_options
)
- http_server.listen(port)
- tornado.ioloop.IOLoop.instance().start()
+ http_server.listen(port, address)
+ port = port
+ for i in http_server._sockets.values():
+ sn = i.getsockname()
+ if sn[0] == address:
+ port = sn[1]
+ return port
+
+def run():
+ tornado.ioloop.IOLoop.instance().start()