Created
March 7, 2021 01:43
-
-
Save gh640/3c54c2eb5a8af889e3ab5f49cc4befc6 to your computer and use it in GitHub Desktop.
Revisions
-
gh640 revised this gist
Mar 7, 2021 . No changes.There are no files selected for viewing
-
gh640 created this gist
Mar 7, 2021 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,37 @@ """Simple https server for development.""" import ssl from http.server import HTTPServer, SimpleHTTPRequestHandler CERTFILE = './localhost.pem' def main(): https_server(certfile=CERTFILE) def https_server(*, certfile): print('`https_server()` starts...') context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) context.load_cert_chain(CERTFILE) server_address = ('', 443) with HTTPServer(server_address, SimpleHTTPRequestHandler) as httpd: httpd.socket = context.wrap_socket(httpd.socket, server_side=True) print_server_info(httpd) try: httpd.serve_forever() except Exception as e: httpd.server_close() raise e def print_server_info(server): print(f"""Server info: name: {server.server_name} address: {server.server_address} """) if __name__ == "__main__": main()