blob: 5b845d81a69b19773c66ea4fb61a1a9065a88c47 [file] [log] [blame]
Jesse Andrews64164072011-11-05 22:15:50 -07001import sys
2from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
3from SimpleHTTPServer import SimpleHTTPRequestHandler
4
5def main(host, port, HandlerClass = SimpleHTTPRequestHandler,
6 ServerClass = HTTPServer, protocol="HTTP/1.0"):
7 """simple http server that listens on a give address:port"""
8
9 server_address = (host, port)
10
11 HandlerClass.protocol_version = protocol
12 httpd = ServerClass(server_address, HandlerClass)
13
14 sa = httpd.socket.getsockname()
15 print "Serving HTTP on", sa[0], "port", sa[1], "..."
16 httpd.serve_forever()
17
18if __name__ == '__main__':
19 if sys.argv[1:]:
20 address = sys.argv[1]
21 else:
22 address = '0.0.0.0'
23 if ':' in address:
24 host, port = address.split(':')
25 else:
26 host = address
27 port = 8080
28
29 main(host, int(port))