Skip to content

Commit

Permalink
feat: support HTTP response compression in api server (#2680)
Browse files Browse the repository at this point in the history
  • Loading branch information
bowenliang123 authored Mar 5, 2024
1 parent 38e5952 commit 552f319
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
2 changes: 2 additions & 0 deletions api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from extensions import (
ext_celery,
ext_code_based_extension,
ext_compress,
ext_database,
ext_hosting_provider,
ext_login,
Expand Down Expand Up @@ -96,6 +97,7 @@ def create_app(test_config=None) -> Flask:
def initialize_extensions(app):
# Since the application instance is now created, pass it to each Flask
# extension instance to bind it to the Flask application instance (app)
ext_compress.init_app(app)
ext_code_based_extension.init()
ext_database.init_app(app)
ext_migrate.init(app, db)
Expand Down
2 changes: 2 additions & 0 deletions api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,8 @@ def __init__(self):

self.BATCH_UPLOAD_LIMIT = get_env('BATCH_UPLOAD_LIMIT')

self.API_COMPRESSION_ENABLED = get_bool_env('API_COMPRESSION_ENABLED')


class CloudEditionConfig(Config):

Expand Down
10 changes: 10 additions & 0 deletions api/extensions/ext_compress.py
Original file line number Diff line number Diff line change
@@ -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)

1 change: 1 addition & 0 deletions api/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ beautifulsoup4==4.12.2
flask~=3.0.1
Flask-SQLAlchemy~=3.0.5
SQLAlchemy~=1.4.28
Flask-Compress~=1.14
flask-login~=0.6.3
flask-migrate~=4.0.5
flask-restful~=0.3.10
Expand Down

0 comments on commit 552f319

Please sign in to comment.