Add `exclude_content_types` parameter to `GZipMiddleware`

Merged
KL
3mo ago
+114-8

Add a keyword-only exclude_content_types parameter to GZipMiddleware, replacing the hardcoded exclusion check.

  • A response is excluded when its Content-Type media type equals an entry, or matches a type/* wildcard entry (e.g. "image/*"). Matching is case-insensitive and ignores parameters like charset; configured values are normalized the same way.
  • Defaults to DEFAULT_EXCLUDED_CONTENT_TYPES (("text/event-stream",)), which stays importable so the defaults can be extended rather than replaced.
  • Both responders accept the parameter keyword-only with a default, so direct instantiation keeps working (same pattern as #3415).

Supersedes #3091 and #3040, and implements the feature requested in #3414.

Wire-visible deltas from the previous prefix check, for the release notes: matching is now case-insensitive, text/event-stream-foo no longer matches, and reassigning DEFAULT_EXCLUDED_CONTENT_TYPES at runtime no longer takes effect (the exclusions are read at construction).

AI Disclaimer

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