Created
August 17, 2019 11:15
-
-
Save Magicloud/ef9ac68e71b844b50a53e3939f38d14f to your computer and use it in GitHub Desktop.
Basic HTTPS service
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/python3 | |
from http.server import HTTPServer, BaseHTTPRequestHandler | |
import ssl | |
import socket | |
class SimpleHTTPRequestHandler(BaseHTTPRequestHandler): | |
def do_GET(self): | |
self.send_response(200) | |
self.send_header("Content-Type", "text/html") | |
self.end_headers() | |
self.wfile.write(b"<!doctype html><head><title>HOSTNAME</title></head><body><h1>") | |
self.wfile.write(socket.gethostname().encode()) | |
self.wfile.write(b"</h1></body></html>") | |
httpd = HTTPServer(("0.0.0.0", 443), SimpleHTTPRequestHandler) | |
httpd.socket = ssl.wrap_socket (httpd.socket, | |
keyfile="dePK.pem", | |
certfile="cert.pem", | |
server_side=True) | |
httpd.serve_forever() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment