Skip to content

Instantly share code, notes, and snippets.

@cheeming
Forked from wendyjap/test_https_server.py
Last active August 29, 2015 14:05
Show Gist options
  • Save cheeming/2854f3a5b31765a5549c to your computer and use it in GitHub Desktop.
Save cheeming/2854f3a5b31765a5549c to your computer and use it in GitHub Desktop.
# the following is one way to generate self-signed cert for this test server
# openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.crt
from http.server import HTTPServer,SimpleHTTPRequestHandler
from socketserver import BaseServer
import ssl
HOSTNAME = 'localhost'
HTTPS_PORT = 8443
httpd = HTTPServer((HOSTNAME, HTTPS_PORT), SimpleHTTPRequestHandler)
httpd.socket = ssl.wrap_socket(httpd.socket, keyfile='server.key', certfile='server.crt', server_side=True)
print('Running https server on port {0}. Check it out with open https://{1}:{0}'.format(HTTPS_PORT, HOSTNAME))
httpd.serve_forever()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment