about summary refs log tree commit diff
path: root/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'main.py')
-rw-r--r--main.py110
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()