feat: support HTTP response compression in api server (#2680)

This commit is contained in:
Bowen Liang 2024-03-05 14:45:22 +08:00 committed by GitHub
parent 38e5952417
commit 552f319b9d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 15 additions and 0 deletions

View File

@ -26,6 +26,7 @@ from config import CloudEditionConfig, Config
from extensions import ( from extensions import (
ext_celery, ext_celery,
ext_code_based_extension, ext_code_based_extension,
ext_compress,
ext_database, ext_database,
ext_hosting_provider, ext_hosting_provider,
ext_login, ext_login,
@ -96,6 +97,7 @@ def create_app(test_config=None) -> Flask:
def initialize_extensions(app): def initialize_extensions(app):
# Since the application instance is now created, pass it to each Flask # Since the application instance is now created, pass it to each Flask
# extension instance to bind it to the Flask application instance (app) # extension instance to bind it to the Flask application instance (app)
ext_compress.init_app(app)
ext_code_based_extension.init() ext_code_based_extension.init()
ext_database.init_app(app) ext_database.init_app(app)
ext_migrate.init(app, db) ext_migrate.init(app, db)

View File

@ -293,6 +293,8 @@ class Config:
self.BATCH_UPLOAD_LIMIT = get_env('BATCH_UPLOAD_LIMIT') self.BATCH_UPLOAD_LIMIT = get_env('BATCH_UPLOAD_LIMIT')
self.API_COMPRESSION_ENABLED = get_bool_env('API_COMPRESSION_ENABLED')
class CloudEditionConfig(Config): class CloudEditionConfig(Config):

View File

@ -0,0 +1,10 @@
from flask import Flask
def init_app(app: Flask):
if app.config.get('API_COMPRESSION_ENABLED', False):
from flask_compress import Compress
compress = Compress()
compress.init_app(app)

View File

@ -3,6 +3,7 @@ beautifulsoup4==4.12.2
flask~=3.0.1 flask~=3.0.1
Flask-SQLAlchemy~=3.0.5 Flask-SQLAlchemy~=3.0.5
SQLAlchemy~=1.4.28 SQLAlchemy~=1.4.28
Flask-Compress~=1.14
flask-login~=0.6.3 flask-login~=0.6.3
flask-migrate~=4.0.5 flask-migrate~=4.0.5
flask-restful~=0.3.10 flask-restful~=0.3.10