Last active
September 14, 2020 09:52
-
-
Save NoahCardoza/f9c6c97d7d52322ea930c8b8d031099d to your computer and use it in GitHub Desktop.
An HTTP server that will handle both HTTP and HTTPS in Python 3
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
from http.server import HTTPServer | |
class HTTPAndHTTPSServer(HTTPServer): | |
def __init__(ssl_context, *args, **kwargs): | |
super().__init__(*args, **kwargs) | |
self.ssl_context = ssl_context | |
def get_request(self): | |
conn, addr = self.socket.accept() | |
if self.context and conn.recv(1, socket.MSG_PEEK) == b'\x16': | |
conn = self.ssl_context.wrap_socket(conn, server_side=True) | |
return conn, addr |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment