about summary refs log tree commit diff
diff options
context:
space:
mode:
authorUltraQbik <no1skill@yandex.ru>2024-08-27 22:22:58 +0300
committerUltraQbik <no1skill@yandex.ru>2024-08-27 22:22:58 +0300
commit0fd9990c013be4c29cf5829fcc256dce677da9b1 (patch)
tree9cf491d1d746f5742fe8120143db12d47d6e40fd
parentea9c74bbf5be81ccb6248b53e541b1d2e06d3d07 (diff)
downloadhttpy-0fd9990c013be4c29cf5829fcc256dce677da9b1.tar.gz
httpy-0fd9990c013be4c29cf5829fcc256dce677da9b1.zip
change brotli to gzip
-rw-r--r--main.py2
-rw-r--r--requirements.txt1
-rw-r--r--src/file_man.py14
3 files changed, 6 insertions, 11 deletions
diff --git a/main.py b/main.py
index 3f3aace..3bfdeeb 100644
--- a/main.py
+++ b/main.py
@@ -168,8 +168,8 @@ class HTTPServer:
 
         # Remove self from thread list and close the connection
         self.client_threads.remove(threading.current_thread())
-        client.close()
         self.semaphore.release()
+        client.close()
 
     def _client_request_handler(self, client: _usocket, request: Request):
         """
diff --git a/requirements.txt b/requirements.txt
index 96cf00a..81854b1 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -1,2 +1 @@
-Brotli==1.1.0
 htmlmin==0.1.12
diff --git a/src/file_man.py b/src/file_man.py
index e16d448..4538218 100644
--- a/src/file_man.py
+++ b/src/file_man.py
@@ -79,7 +79,7 @@ def compress_path_map(path_map: dict[str, dict[str, Any]], path_prefix: str = "c
     Compresses all files using brotli
     """
 
-    import brotli
+    import gzip
     import htmlmin
     if not os.path.exists(path_prefix):
         os.mkdir(path_prefix)
@@ -90,28 +90,24 @@ def compress_path_map(path_map: dict[str, dict[str, Any]], path_prefix: str = "c
         if not os.path.exists((dirs := os.path.dirname(filepath))):  # add missing folders
             os.makedirs(dirs)
         if not os.path.exists(filepath) or regen:
-            # brotli compress
             if val["headers"]["Content-Type"] == "text/html":
                 with open(filepath, "wb") as comp:
                     with open(val["path"], "rb") as file:
                         comp.write(
-                            brotli.compress(htmlmin.minify(
+                            gzip.compress(htmlmin.minify(
                                 file.read().decode("utf-8"),
                                 remove_comments=True,
                                 remove_empty_space=True,
                                 remove_all_empty_space=True,
                                 reduce_boolean_attributes=True).encode("utf-8")))
             else:
-                with open(filepath, "wb") as comp:
-                    br = brotli.Compressor()
+                with gzip.open(filepath, "wb") as comp:
                     with open(val["path"], "rb") as file:
-                        while (chunk := file.read(65536)):
-                            br.process(chunk)
-                            comp.write(br.flush())
+                        comp.writelines(file)
 
         val["path"] = filepath
         val["headers"]["Content-Length"] = os.path.getsize(filepath)
-        val["headers"]["Content-Encoding"] = "br"
+        val["headers"]["Content-Encoding"] = "gzip"
 
     if FILE_MAN_VERBOSE:
         print("COMPRESSED PATH:")