Skip to content

Commit

Permalink
Add GZipMiddleware to compress response content. (apache#43707)
Browse files Browse the repository at this point in the history
  • Loading branch information
tirkarthi authored Nov 6, 2024
1 parent b89f43e commit f05716b
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions airflow/api_fastapi/core_api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from fastapi.middleware.gzip import GZipMiddleware
from starlette.requests import Request
from starlette.responses import HTMLResponse
from starlette.staticfiles import StaticFiles
Expand Down Expand Up @@ -113,4 +114,9 @@ def init_config(app: FastAPI) -> None:
allow_headers=allow_headers,
)

# Compress responses greater than 1kB with optimal compression level as 5
# with level ranging from 1 to 9 with 1 (fastest, least compression)
# and 9 (slowest, most compression)
app.add_middleware(GZipMiddleware, minimum_size=1024, compresslevel=5)

app.state.secret_key = conf.get("webserver", "secret_key")

0 comments on commit f05716b

Please sign in to comment.