From 035235861190cf7f3d1288fdc11f1a3f70cedd8a Mon Sep 17 00:00:00 2001 From: n9k Date: Thu, 10 Mar 2022 13:58:17 +0000 Subject: [PATCH] Compress some responses Adds dependency `quart-compress` --- anonstream/__init__.py | 10 ++++++++++ requirements.txt | 2 ++ 2 files changed, 12 insertions(+) diff --git a/anonstream/__init__.py b/anonstream/__init__.py index 8c8a358..e8c0b14 100644 --- a/anonstream/__init__.py +++ b/anonstream/__init__.py @@ -7,12 +7,15 @@ import toml from collections import OrderedDict from quart import Quart +from quart_compress import Compress from werkzeug.security import generate_password_hash from anonstream.utils.captcha import create_captcha_factory, create_captcha_signer from anonstream.utils.colour import color_to_colour from anonstream.utils.user import generate_token +compress = Compress() + def create_app(config_file): with open(config_file) as fp: config = toml.load(fp) @@ -112,4 +115,11 @@ def create_app(config_file): import anonstream.routes import anonstream.tasks + # Compress some responses + compress.init_app(app) + app.config.update({ + "COMPRESS_MIN_SIZE": 2048, + "COMPRESS_LEVEL": 9, + }) + return app diff --git a/requirements.txt b/requirements.txt index b42fa16..4bc316a 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ aiofiles==0.8.0 asgiref==3.5.0 blinker==1.4 +Brotli==1.0.9 git+https://github.com/lepture/captcha@27920681b86c27c990da484984f673dba1dd47e5#egg=captcha click==8.0.4 h11==0.13.0 @@ -16,6 +17,7 @@ MarkupSafe==2.1.0 Pillow==9.0.1 priority==2.0.0 quart==0.16.3 +quart-compress==0.2.1 toml==0.10.2 uvicorn==0.17.5 Werkzeug==2.0.3