Expand default excluded content types in `GZipMiddleware`

Merged
KL
3mo ago
+52-3

Extend DEFAULT_EXCLUDED_CONTENT_TYPES beyond text/event-stream to cover already-compressed formats, so the middleware stops wasting CPU re-compressing them out of the box: zip/gzip archives, common raster image types (image/png, image/jpeg, image/webp, image/gif, image/avif), video/*, audio/*, and WOFF fonts.

Implements the defaults expansion requested in #3040 and #3091 (and Streamlit's subclass workaround). Two deliberate omissions, both grounded in what these formats actually are:

  • No image/*: image/svg+xml is text and gzips to roughly half size (tower-http carves out the same exception). Raster types are enumerated instead.
  • No font/*: only WOFF/WOFF2 carry internal compression - font/ttf/font/otf are uncompressed table formats that gzip well.

Behavior change: responses with these content types are no longer compressed by default. Restore the old behavior per type with e.g. exclude_content_types=("text/event-stream",).

Stacked on #3420.

AI Disclaimer

This PR was developed with the assistance of either Claude or Codex. I've reviewed and verified the changes.