about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUltraQbik <no1skill@yandex.ru>2024-08-20 20:38:27 +0300
committerUltraQbik <no1skill@yandex.ru>2024-08-20 20:38:27 +0300
commitcb26d696dec66be1d163dd3a89ae0aa9bcb4cde9 (patch)
tree36096bbf502e87eb65bf9f3da19ec48aaad59a5e
parent230d8db6784f78cdd3623f37356fdb8a296b9d8f (diff)
downloadhttpy-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
-rw-r--r--.gitignore1
-rw-r--r--main.py15
2 files changed, 14 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index 9a9ce1f..e8e5303 100644
--- a/.gitignore
+++ b/.gitignore
@@ -162,3 +162,4 @@ cython_debug/
 .idea/
 /cert.pem
 /key.pem
+/www/yes.txt
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] = []