Created
February 4, 2015 12:18
-
-
Save jorge-lavin/5361f9fe68b6a092e64a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
A simple HTTP Server. It admits port and ip as optional parameters | |
""" | |
import sys | |
import BaseHTTPServer | |
from SimpleHTTPServer import SimpleHTTPRequestHandler | |
HandlerClass = SimpleHTTPRequestHandler | |
ServerClass = BaseHTTPServer.HTTPServer | |
Protocol = "HTTP/1.0" | |
try: | |
sys.argv[1] | |
port = int(sys.argv[1]) | |
except IndexError: | |
port = 8000 | |
try: | |
sys.argv[2] | |
ip = sys.argv[2] | |
except IndexError: | |
ip = '' | |
server_address = (ip, port) | |
HandlerClass.protocol_version = Protocol | |
httpd = ServerClass(server_address, HandlerClass) | |
sa = httpd.socket.getsockname() | |
print "Serving HTTP on", sa[0], "port", sa[1], "..." | |
httpd.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment