Created
May 3, 2017 23:45
-
-
Save mneil/553459c23a6afbabf461c062890577aa to your computer and use it in GitHub Desktop.
Python Static Server w/SSL
This file contains 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
import BaseHTTPServer, SimpleHTTPServer | |
import ssl, os, sys | |
port = int(sys.argv[1]) if len(sys.argv) > 1 else 4443 | |
cwd = os.path.dirname(os.path.realpath(__file__)) | |
pem = os.path.join( cwd, 'mycert.pem' ) | |
os.chdir(cwd) | |
class MyHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler): | |
def end_headers(self): | |
self.send_my_headers() | |
SimpleHTTPServer.SimpleHTTPRequestHandler.end_headers(self) | |
def send_my_headers(self): | |
self.send_header("Cache-Control", "public, max-age=3600") | |
httpd = BaseHTTPServer.HTTPServer(('0.0.0.0', port), MyHTTPRequestHandler) | |
httpd.socket = ssl.wrap_socket(httpd.socket, certfile=pem, server_side=True) | |
print 'python server watching {} listening on {}'.format(cwd, port) | |
httpd.serve_forever(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment