Skip to content

Instantly share code, notes, and snippets.

@orip
Last active August 16, 2021 21:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save orip/0c6c7d43a68541c8ee91a7e1fcc9af2f to your computer and use it in GitHub Desktop.
Save orip/0c6c7d43a68541c8ee91a7e1fcc9af2f to your computer and use it in GitHub Desktop.
Simple Python 3 HTTPS server that acts as much as possible like `python -m http.server`
#!/usr/bin/env python3
# Inspired by https://stackoverflow.com/a/19706670/37020 by @mfukar
import http.server, ssl
CERTFILE="server.pem"
class SSLHTTPServer(http.server.ThreadingHTTPServer):
def __init__(self, *args, certfile=CERTFILE, **kwargs):
super().__init__(*args, **kwargs)
self.socket = ssl.wrap_socket(self.socket, server_side=True, certfile=certfile, ssl_version=ssl.PROTOCOL_TLS)
http.server.test(ServerClass=SSLHTTPServer, HandlerClass=http.server.SimpleHTTPRequestHandler)
@orip
Copy link
Author

orip commented Aug 16, 2021

Inspired by @mfukar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment