Skip to content

Exclude image types from compression#137

Merged
kevinmcconnell merged 1 commit into
mainfrom
compression-exclude-image-types
Jun 24, 2026
Merged

Exclude image types from compression#137
kevinmcconnell merged 1 commit into
mainfrom
compression-exclude-image-types

Conversation

@kevinmcconnell

@kevinmcconnell kevinmcconnell commented Jun 24, 2026

Copy link
Copy Markdown
Collaborator

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

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.
Copilot AI review requested due to automatic review settings June 24, 2026 13:03

Copilot AI 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.

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.ContentTypeFilter that builds on gzhttp.DefaultContentTypeFilter and additionally excludes common compressed image MIME types.
  • Update the existing handler integration test to validate non-compression for image/png (not just JPEG, which gzhttp already 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.

@kevinmcconnell kevinmcconnell merged commit 6c45e38 into main Jun 24, 2026
7 checks passed
@kevinmcconnell kevinmcconnell deleted the compression-exclude-image-types branch June 24, 2026 13:08
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.

2 participants