summaryrefslogtreecommitdiffstats
path: root/src/browse.py
diff options
context:
space:
mode:
authorTej Chajed <tchajed@mit.edu>2017-03-09 18:57:22 (GMT)
committerTej Chajed <tchajed@mit.edu>2017-03-09 18:57:22 (GMT)
commit8a32d21b674c144ac948e037d4eac64352f09849 (patch)
treef04833f8bb5c1e1ca3fb67e2571b18b48b117355 /src/browse.py
parentfb3c70049b82d53101fc6086a1699ecf16966792 (diff)
downloadNinja-8a32d21b674c144ac948e037d4eac64352f09849.zip
Ninja-8a32d21b674c144ac948e037d4eac64352f09849.tar.gz
Ninja-8a32d21b674c144ac948e037d4eac64352f09849.tar.bz2
browse: Bind to localhost by default
Previously the browse server would bind to "", which is translated to 0.0.0.0 (all interfaces), and then the hostname as retrieved by socket.gethostname() was presented to the user. The hostname is now "localhost" by default and is configurable, so the original behavior is achieved with `ninja -t browse -a ""`.
Diffstat (limited to 'src/browse.py')
-rwxr-xr-xsrc/browse.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/browse.py b/src/browse.py
index 4b4faa8..64a16f2 100755
--- a/src/browse.py
+++ b/src/browse.py
@@ -193,6 +193,8 @@ class RequestHandler(httpserver.BaseHTTPRequestHandler):
parser = argparse.ArgumentParser(prog='ninja -t browse')
parser.add_argument('--port', '-p', default=8000, type=int,
help='Port number to use (default %(default)d)')
+parser.add_argument('--hostname', '-a', default='localhost', type=str,
+ help='Hostname to bind to (default %(default)s)')
parser.add_argument('--no-browser', action='store_true',
help='Do not open a webbrowser on startup.')
@@ -205,9 +207,11 @@ parser.add_argument('initial_target', default='all', nargs='?',
args = parser.parse_args()
port = args.port
-httpd = httpserver.HTTPServer(('',port), RequestHandler)
+hostname = args.hostname
+httpd = httpserver.HTTPServer((hostname,port), RequestHandler)
try:
- hostname = socket.gethostname()
+ if hostname == "":
+ hostname = socket.gethostname()
print('Web server running on %s:%d, ctl-C to abort...' % (hostname,port) )
print('Web server pid %d' % os.getpid(), file=sys.stderr )
if not args.no_browser: