diff options
| author | UltraQbik <no1skill@yandex.ru> | 2024-08-20 20:38:27 +0300 |
|---|---|---|
| committer | UltraQbik <no1skill@yandex.ru> | 2024-08-20 20:38:27 +0300 |
| commit | cb26d696dec66be1d163dd3a89ae0aa9bcb4cde9 (patch) | |
| tree | 36096bbf502e87eb65bf9f3da19ec48aaad59a5e /main.py | |
| parent | 230d8db6784f78cdd3623f37356fdb8a296b9d8f (diff) | |
| download | httpy-cb26d696dec66be1d163dd3a89ae0aa9bcb4cde9.tar.gz httpy-cb26d696dec66be1d163dd3a89ae0aa9bcb4cde9.zip | |
Update to use HTTPS instead of HTTP
That was very painful, but it does seem to work now with https using ssl standard library
Diffstat (limited to 'main.py')
| -rw-r--r-- | main.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/main.py b/main.py index 4f82213..2cfceb8 100644 --- a/main.py +++ b/main.py @@ -3,6 +3,7 @@ The mighty silly webserver written in python for no good reason """ +import ssl import time import json import gzip @@ -86,9 +87,19 @@ class HTTPServer: """ def __init__(self, *, port: int, packet_size: int = 2048): - self.bind_port: int = port + # ssl context + self.context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER) + self.context.load_cert_chain( + certfile=r"C:\Certbot\live\qubane.ddns.net\fullchain.pem", # use your own path here + keyfile=r"C:\Certbot\live\qubane.ddns.net\privkey.pem" # here too + ) + self.context.check_hostname = False + + # sockets + self.socket: ssl.SSLSocket = self.context.wrap_socket( + socket.socket(socket.AF_INET, socket.SOCK_STREAM), server_side=True) self.packet_size: int = packet_size - self.socket: socket.socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + self.bind_port: int = port self.clients: list[socket.socket] = [] |