From 7b804f823d3c1a96192f5d9d1d0ae286f47579b7 Mon Sep 17 00:00:00 2001 From: UltraQbik Date: Tue, 20 Aug 2024 18:34:41 +0300 Subject: Get rid of htmlmin (use just gzip) --- main.py | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'main.py') 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): """ -- cgit 1.4.1