Add excluded_content_types parameter to GZipMiddleware#3091
Add excluded_content_types parameter to GZipMiddleware#3091
excluded_content_types parameter to GZipMiddleware#3091Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds the ability to customize which content types should be excluded from gzip compression in GZipMiddleware. It introduces two new keyword-only parameters: excluded_content_types to completely replace the default exclusions, and additional_excluded_content_types to add more exclusions while keeping the defaults. Additionally, it expands the default excluded content types to include already-compressed formats.
Changes:
- Added
excluded_content_typesandadditional_excluded_content_typesparameters toGZipMiddleware - Extended DEFAULT_EXCLUDED_CONTENT_TYPES to include application/zip, application/gzip, and application/x-gzip
- Propagated the excluded_content_types parameter through IdentityResponder and GZipResponder
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| excluded_content_types: tuple[str, ...] = DEFAULT_EXCLUDED_CONTENT_TYPES, | ||
| additional_excluded_content_types: tuple[str, ...] = (), |
There was a problem hiding this comment.
The new excluded_content_types and additional_excluded_content_types parameters lack test coverage. Consider adding tests that verify:
- Custom content types can be excluded from compression using
excluded_content_types - Additional content types can be excluded using
additional_excluded_content_types - The default excluded content types (application/zip, application/gzip, application/x-gzip) are properly excluded from compression
| excluded_content_types: tuple[str, ...] = DEFAULT_EXCLUDED_CONTENT_TYPES, | ||
| additional_excluded_content_types: tuple[str, ...] = (), |
There was a problem hiding this comment.
The documentation in docs/middleware.md should be updated to describe the new excluded_content_types and additional_excluded_content_types parameters. The current documentation at lines 240-244 mentions the default exclusion behavior but doesn't document that these can now be customized.
| DEFAULT_EXCLUDED_CONTENT_TYPES = ( | ||
| "text/event-stream", | ||
| "application/zip", | ||
| "application/gzip", | ||
| "application/x-gzip", | ||
| ) |
There was a problem hiding this comment.
Adding new content types to DEFAULT_EXCLUDED_CONTENT_TYPES is a breaking change. While it's sensible to exclude already-compressed formats (application/zip, application/gzip, application/x-gzip), this changes the default behavior for existing users. Consider documenting this as a breaking change in the release notes and ensuring it's mentioned in the PR description or migration guide.
No description provided.