about summary refs log tree commit diff
path: root/main.py
diff options
context:
space:
mode:
authorUltraQbik <no1skill@yandex.ru>2024-08-20 18:34:41 +0300
committerUltraQbik <no1skill@yandex.ru>2024-08-20 18:34:41 +0300
commit7b804f823d3c1a96192f5d9d1d0ae286f47579b7 (patch)
tree525603097afbeea8b2c9e48a135ed82f99d0318a /main.py
parentd733e209619e544f74a6e933dbe367e9a48fc62b (diff)
downloadhttpy-7b804f823d3c1a96192f5d9d1d0ae286f47579b7.tar.gz
httpy-7b804f823d3c1a96192f5d9d1d0ae286f47579b7.zip
Get rid of htmlmin (use just gzip)
Diffstat (limited to 'main.py')
-rw-r--r--main.py25
1 files changed, 23 insertions, 2 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):
         """