Last active
August 16, 2021 21:24
-
-
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`
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
#!/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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Inspired by @mfukar