Skip to content

Add exclude_content_types parameter to GZipMiddleware - #3418

Merged
Kludex merged 2 commits into
mainfrom
gzip-exclude-content-types
Aug 6, 2026
Merged

Kludex merged 2 commits into
mainfrom
gzip-exclude-content-types

Conversation

@Kludex

@Kludex Kludex commented Aug 6, 2026

Copy link
Copy Markdown
Owner

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 Default thread_minimum_size in GZipResponder #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.

Review in cubic

@github-actions

github-actions Bot commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

Re-trigger cubic

@codspeed

codspeed Bot commented Aug 6, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 136 untouched benchmarks


Comparing gzip-exclude-content-types (af1e1c3) with main (f752519)

Open in CodSpeed

from starlette.datastructures import Headers, MutableHeaders
from starlette.types import ASGIApp, Message, Receive, Scope, Send

DEFAULT_EXCLUDED_CONTENT_TYPES = ("text/event-stream",)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "EXCLUDED" was a mistake.

It should have been exclude.

@Kludex
Kludex enabled auto-merge (squash) August 6, 2026 19:37
@Kludex
Kludex disabled auto-merge August 6, 2026 19:42
@Kludex
Kludex enabled auto-merge (squash) August 6, 2026 20:32
@Kludex
Kludex disabled auto-merge August 6, 2026 20:33
@Kludex
Kludex merged commit 99b7cc6 into main Aug 6, 2026
4 checks passed
@Kludex
Kludex deleted the gzip-exclude-content-types branch August 6, 2026 20:33
@Kludex Kludex mentioned this pull request Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant