Skip to content

Instantly share code, notes, and snippets.

@mateusza
Created January 18, 2019 00:32
Show Gist options
  • Save mateusza/7d1a070932c42eab4d3b7f5c111b1c6b to your computer and use it in GitHub Desktop.
Save mateusza/7d1a070932c42eab4d3b7f5c111b1c6b to your computer and use it in GitHub Desktop.
import ssl
import BaseHTTPServer
import SimpleHTTPServer
class HTTPSServer( BaseHTTPServer.HTTPServer ):
def __init__( self, port, RQ, cert ):
BaseHTTPServer.HTTPServer.__init__( self, port, RQ )
self.socket = ssl.wrap_socket( self.socket, certfile=cert )
if __name__ == '__main__':
def usage():
print "usage: %s [OPT]" % sys.argv[0]
print " --bind (-b) ADDRESS"
print " --port (-p) PORT"
print " --cert (-c) PEM FILE"
print " --help (-h)"
import getopt
import sys
try:
opts, args = getopt.getopt( sys.argv[1:], "b:p:c:h", [ "bind=", "port=", "cert=", "help" ] )
except getopt.GetoptError as err:
print str(err)
sys.exit(2)
cert = "server.pem"
bind = "0.0.0.0"
port = 8443
for opt, arg in opts:
if opt in ('-b','--bind' ):
bind = arg
elif opt in ( '-p','--port' ):
port = int( arg )
elif opt in ( '-c', '--cert' ):
cert = arg
elif opt in ( '-h', '--help' ):
usage()
sys.exit(0)
print "Starting server at https://%s:%d/ [cert %s]" % ( bind,port,cert)
HTTPSServer( (bind, port), SimpleHTTPServer.SimpleHTTPRequestHandler, cert ).serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment