-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttps-server.py
More file actions
24 lines (21 loc) · 847 Bytes
/
https-server.py
File metadata and controls
24 lines (21 loc) · 847 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python3
import http.server
import ssl
import socketserver
PORT = 8443
class HTTPServer(socketserver.TCPServer):
def __init__(self, server_address, RequestHandlerClass):
super().__init__(server_address, RequestHandlerClass)
self.socket = ssl.wrap_socket(self.socket,
keyfile='key.pem',
certfile='cert.pem',
server_side=True)
if __name__ == '__main__':
with HTTPServer(('localhost', PORT), http.server.SimpleHTTPRequestHandler) as httpd:
print(f'Serving HTTPS on https://localhost:{PORT}')
print('Press Ctrl+C to stop')
try:
httpd.serve_forever()
except KeyboardInterrupt:
print('\nShutting down server...')
httpd.shutdown()