summaryrefslogtreecommitdiffstats
path: root/Lib/http/server.py
diff options
context:
space:
mode:
authorSenthil Kumaran <senthil@uthcode.com>2013-09-15 16:37:27 (GMT)
committerSenthil Kumaran <senthil@uthcode.com>2013-09-15 16:37:27 (GMT)
commitdefe7f4c62b992380fdda2833bb46a6505c839f4 (patch)
treedb470d7591c9fa72ff25f4b8c052dcb78c2cccf7 /Lib/http/server.py
parent5642ff9d8eefb0068eeb99c31320d3c6a319ea88 (diff)
downloadcpython-defe7f4c62b992380fdda2833bb46a6505c839f4.zip
cpython-defe7f4c62b992380fdda2833bb46a6505c839f4.tar.gz
cpython-defe7f4c62b992380fdda2833bb46a6505c839f4.tar.bz2
Expose --bind argument for http.server, enable http.server to bind to a user
specified network interface. Patch contributed by Malte Swart. Addresses issue #17764. HG :Enter commit message. Lines beginning with 'HG:' are removed.
Diffstat (limited to 'Lib/http/server.py')
-rw-r--r--Lib/http/server.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/Lib/http/server.py b/Lib/http/server.py
index 87d8378..2ddef52 100644
--- a/Lib/http/server.py
+++ b/Lib/http/server.py
@@ -1186,15 +1186,15 @@ class CGIHTTPRequestHandler(SimpleHTTPRequestHandler):
self.log_message("CGI script exited OK")
-def test(HandlerClass = BaseHTTPRequestHandler,
- ServerClass = HTTPServer, protocol="HTTP/1.0", port=8000):
+def test(HandlerClass=BaseHTTPRequestHandler,
+ ServerClass=HTTPServer, protocol="HTTP/1.0", port=8000, bind=""):
"""Test the HTTP request handler class.
This runs an HTTP server on port 8000 (or the first command line
argument).
"""
- server_address = ('', port)
+ server_address = (bind, port)
HandlerClass.protocol_version = protocol
httpd = ServerClass(server_address, HandlerClass)
@@ -1212,12 +1212,16 @@ if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--cgi', action='store_true',
help='Run as CGI Server')
+ parser.add_argument('--bind', '-b', default='', metavar='ADDRESS',
+ help='Specify alternate bind address '
+ '[default: all interfaces]')
parser.add_argument('port', action='store',
default=8000, type=int,
nargs='?',
help='Specify alternate port [default: 8000]')
args = parser.parse_args()
if args.cgi:
- test(HandlerClass=CGIHTTPRequestHandler, port=args.port)
+ handler_class = CGIHTTPRequestHandler
else:
- test(HandlerClass=SimpleHTTPRequestHandler, port=args.port)
+ handler_class = SimpleHTTPRequestHandler
+ test(HandlerClass=handler_class, port=args.port, bind=args.bind)