Exclude image types from compression#137
Merged
Merged
Conversation
Excludes the set of common already-compressed image types, so that we don't waste time trying to gzip a compressed image. These types are in addition to gzhttp's existing default list. Interestingly gzhttp already excludes JPEG by default, but not the other types. We still include JPEG in our own exclusion list for clarity.
There was a problem hiding this comment.
Pull request overview
This PR prevents gzip compression from being applied to common already-compressed image content types (e.g., PNG/WebP/AVIF/HEIC), avoiding wasted CPU/time and ensuring image responses are served as-is.
Changes:
- Add a custom
gzhttp.ContentTypeFilterthat builds ongzhttp.DefaultContentTypeFilterand additionally excludes common compressed image MIME types. - Update the existing handler integration test to validate non-compression for
image/png(not just JPEG, whichgzhttpalready excludes by default). - Add coverage ensuring X-Sendfile-served PNG responses are not gzip-compressed, plus unit tests for the new content-type filter behavior.
Tip
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.
Reviewed changes
Copilot reviewed 3 out of 5 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| internal/compression_handler.go | Introduces a content-type filter to skip gzip for already-compressed image MIME types. |
| internal/compression_handler_test.go | Adds unit tests verifying which content types are compressed vs excluded by the new filter. |
| internal/handler_test.go | Updates/expands integration tests to ensure PNG (including X-Sendfile) is not gzip-compressed. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Excludes the set of common already-compressed image types, so that we don't waste time trying to gzip a compressed image.
These types are in addition to gzhttp's existing default list.
Interestingly gzhttp already excludes JPEG by default, but not the other types. We still include JPEG in our own exclusion list for clarity.
Also closes #134