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 +++++++++++++++++++++++-- www/index.html | 1 - 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 @@

> Server does not use flask or any other similar python web frameworks

> It primarily uses standard python libraries, with 2 libraries being an exception

> aiofiles - for asynchronous file I/O

-

> htmlmin - for making html page slightly smaller (along with gzip)

Where can I see the shitty python code you wrote?

-- cgit 1.4.1