about summary refs log tree commit diff
path: root/main.py
diff options
context:
space:
mode:
authorUltraQbik <no1skill@yandex.ru>2024-08-25 03:13:45 +0300
committerUltraQbik <no1skill@yandex.ru>2024-08-25 03:13:45 +0300
commit619f5707b95b3ff13047f6114e8b89ef665b1100 (patch)
treed507a6671e758a6399584f276eda83ef29240082 /main.py
parent93317bcd56a39fc70020143d6f4e6a615a45111f (diff)
downloadhttpy-619f5707b95b3ff13047f6114e8b89ef665b1100.tar.gz
httpy-619f5707b95b3ff13047f6114e8b89ef665b1100.zip
Add UTF-8 support
Probably useful to have it
Diffstat (limited to 'main.py')
-rw-r--r--main.py12
1 files changed, 7 insertions, 5 deletions
diff --git a/main.py b/main.py
index 599fd85..c7c2f81 100644
--- a/main.py
+++ b/main.py
@@ -28,6 +28,8 @@ path_map = {
     "/test":                {"path": "www/test.html"},
     "/projects":            {"path": "www/projects.html"},
     "/images/*":            {"path": "www/images"},
+    "/js-test":             {"path": "www/js-test.html"},
+    "/scripts/*":           {"path": "www/scripts"},
 }
 
 # API
@@ -163,8 +165,8 @@ class HTTPServer:
             # case "POST":  # Not Implemented
             #     response = self._handle_post(client, request)
             case _:
-                with open(I_PATH_MAP["/err/response"]["path"], "r", encoding="ascii") as file:
-                    data = file.read().format(status_code=str(STATUS_CODE_NOT_FOUND)).encode("ascii")
+                with open(I_PATH_MAP["/err/response"]["path"], "r", encoding="utf8") as file:
+                    data = file.read().format(status_code=str(STATUS_CODE_NOT_FOUND)).encode("utf8")
                 response = Response(data, STATUS_CODE_NOT_FOUND)
 
         # process header data
@@ -180,7 +182,7 @@ class HTTPServer:
         # generate basic message
         message = b'HTTP/1.1 ' + response.status.__bytes__() + b'\r\n'
         for key, value in response.headers.items():
-            message += f"{key}: {value}\r\n".encode("ascii")
+            message += f"{key}: {value}\r\n".encode("utf8")
         message += b'\r\n'
 
         # send message
@@ -235,9 +237,9 @@ class HTTPServer:
             return APIv1.api_call(client, request)
 
         else:  # assume browser
-            with open(I_PATH_MAP["/err/response"]["path"], "r", encoding="ascii") as file:
+            with open(I_PATH_MAP["/err/response"]["path"], "r", encoding="utf8") as file:
                 data = file.read()
-            data = data.format(status_code=str(STATUS_CODE_NOT_FOUND)).encode("ascii")
+            data = data.format(status_code=str(STATUS_CODE_NOT_FOUND)).encode("utf8")
             return Response(data, STATUS_CODE_NOT_FOUND)
 
     def _handle_post(self, client: ssl.SSLSocket, request: Request) -> Response: