"""gzip JSON responses, leaving streamed exports uncompressed. flask-compress 1.24 has no per-view exempt API; instead ``COMPRESS_STREAMS=False`` leaves streamed responses (the contract and contract_term ``stream_with_context`` exports) uncompressed so they are not buffered into memory before being sent. """ from flask import Flask from flask_compress import Compress from core.config import Config compress = Compress() def setup_compression(app: Flask, config: type[Config]) -> None: """Enable Accept-Encoding-negotiated gzip on ``app`` for sizable JSON/text responses. Always on: gzip is harmless and only applied when the client advertises gzip support. Streamed responses are excluded so the chunked exports are never buffered for compression. """ app.config.setdefault( 'COMPRESS_MIMETYPES', ['application/json', 'text/html', 'text/plain'] ) app.config.setdefault('COMPRESS_MIN_SIZE', 500) app.config.setdefault('COMPRESS_LEVEL', 5) app.config.setdefault('COMPRESS_STREAMS', False) compress.init_app(app)