diff options
| author | UltraQbik <no1skill@yandex.ru> | 2024-08-23 21:28:19 +0300 |
|---|---|---|
| committer | UltraQbik <no1skill@yandex.ru> | 2024-08-23 21:28:19 +0300 |
| commit | 5af071d2e8a745a70fa238230995a83766767cb9 (patch) | |
| tree | 1d60c5031f832678f03734751be0ba9e874e121c /main.py | |
| parent | 9aca00d7265b9d05f908b4201a03b7b0808c5ca1 (diff) | |
| download | httpy-5af071d2e8a745a70fa238230995a83766767cb9.tar.gz httpy-5af071d2e8a745a70fa238230995a83766767cb9.zip | |
Delete old code
Diffstat (limited to 'main.py')
| -rw-r--r-- | main.py | 110 |
1 files changed, 0 insertions, 110 deletions
diff --git a/main.py b/main.py index 3bbd9d4..fdb0432 100644 --- a/main.py +++ b/main.py @@ -235,116 +235,6 @@ class HTTPServer: return None -# class HTTPServer: -# -# def client_handle(self, client: ssl.SSLSocket): -# """ -# Handles client's connection -# """ -# -# while True: -# # receive request from client -# raw_request = self._recvall(client) -# -# if raw_request == b'': -# break -# -# # decode request -# request: Request = Request.create(raw_request) -# -# # # log request -# # async with aiofiles.open("logs.log", "a") as f: -# # await f.write(f"IP: {client.getpeername()[0]}\n{request}\n\n") -# -# threading.Thread(target=self.handle_request, args=[client, request]).start() -# -# def handle_request(self, client: ssl.SSLSocket, request: Request): -# # handle requests -# try: -# match request.type: -# case "GET": -# self.handle_get_request(client, request) -# case _: -# pass -# -# # break on exception -# except Exception as e: -# print(e) -# -# # # close connection (stop page loading) -# # self._close_client(client) -# -# @staticmethod -# def handle_get_request(client: ssl.SSLSocket, request: Request): -# """ -# Handles user's GET request -# """ -# -# # get available compression methods -# compressions = [x.strip() for x in getattr(request, "Accept-Encoding", "").split(",")] -# -# # check if request path is in the PATH_MAP -# if request.path in PATH_MAP: -# # if it is -> return file from that path -# with open(PATH_MAP[request.path]["path"], "rb") as f: -# data = f.read() -# -# # pre-compress data for HTML files -# if PATH_MAP[request.path]["path"][-4:] == "html": -# data = minimize_html(data) -# -# # add brotli compression header (if supported) -# headers = {} -# if "br" in compressions: -# headers["Content-Encoding"] = "br" -# -# # else add gzip compression (if supported) -# elif "gzip" in compressions: -# headers["Content-Encoding"] = "gzip" -# -# # send 200 response with the file to the client -# HTTPServer._send(client, 200, data, headers) -# -# # if it's an API request -# elif (api_version := request.path.split("/")[1]) in API_VERSIONS: -# data = b'' -# headers = {} -# match api_version: -# case "APIv1": -# status, data, headers = APIv1.respond(client, request) -# case _: -# status = 400 -# -# # if status is not 200 -> send bad response -# if status != 200: -# HTTPServer._bad_response(client, status) -# return -# -# # send data if no error -# HTTPServer._send(client, status, data, headers) -# -# # in case of error, return error page -# else: -# HTTPServer._bad_response(client, 404) -# -# @staticmethod -# def _bad_response(client: ssl.SSLSocket, status_code: int): -# """ -# Sends a bad response page to the client. -# :param client: client -# :param status_code: status code -# """ -# -# with open(I_PATH_MAP["/err/response.html"]["path"], "r") as f: -# data = f.read() -# -# # format error response -# data = data.format(status_code=get_response_code(status_code).decode("ascii")) -# -# # send response to the client -# HTTPServer._send(client, status_code, data.encode("ascii")) - - def main(): server = HTTPServer(port=13700) server.start() |