about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--main.py25
-rw-r--r--www/index.html1
2 files changed, 23 insertions, 3 deletions
diff --git a/main.py b/main.py
index 013d410..c49133f 100644
--- a/main.py
+++ b/main.py
@@ -8,7 +8,6 @@ import json
 import gzip
 import socket
 import asyncio
-import htmlmin
 import aiofiles
 import threading
 
@@ -23,6 +22,24 @@ PATH_MAP = {
 }
 
 
+def get_response_code(code: int) -> bytes:
+    match code:
+        case 200:
+            return b'200 OK'
+        case 400:
+            return b'400 Bad Request'
+        case 401:
+            return b'401 Unauthorized'
+        case 403:
+            return b'403 Forbidden'
+        case 404:
+            return b'404 Not Found'
+        case 6969:
+            return b'6969 UwU'
+        case _:  # in any other case return bad request response
+            return get_response_code(400)
+
+
 class Request:
     """
     Just a request
@@ -143,7 +160,11 @@ class HTTPServer:
         :param request: client's request
         """
 
-        pass
+        # check if request path is in the PATH_MAP
+        if request.path in PATH_MAP:
+            # if it is -> return file from that path
+            async with aiofiles.open(PATH_MAP[request.path]["path"], "rb") as f:
+                data = await f.read()
 
     def _close_client(self, client: socket.socket):
         """
diff --git a/www/index.html b/www/index.html
index d860e13..6ba0e5b 100644
--- a/www/index.html
+++ b/www/index.html
@@ -23,7 +23,6 @@
                 <p> > Server does not use flask or any other similar python web frameworks </p>
                 <p> > It primarily uses standard python libraries, with 2 libraries being an exception </p>
                 <p> > <i> aiofiles </i> - for asynchronous file I/O </p>
-                <p> > <i> htmlmin </i> - for making html page slightly smaller (along with gzip) </p>
             </section>
             <section>
                 <h1> Where can I see the shitty python code you wrote? </h1>