Skip to content

HTTP Compression Middleware

Overview

This module provides factories for creating ASGI compression middleware, which can automatically compress API responses to reduce payload size and improve network latency.

How It Works

The CompressionMiddlewareFactory reads the application configuration and, if enabled, returns the configured middleware class (e.g., GZipMiddleware from Starlette) and its settings. This is then added to the main FastAPI/Starlette application's middleware stack.

Configuration

[default.performance.compression]
enabled = true
# Can be "gzip" or "brotli" (if brotli-asgi is installed)
backend = "gzip"
# Don't compress small responses
minimum_size = 500 # bytes

API Reference

nala.athomic.performance.compression.factory.CompressionMiddlewareFactory

Factory to create the configured compression middleware.