feat(gzip): add option to combine default and custom compression decisions#135
Open
kekexiaoai wants to merge 1 commit intogin-contrib:masterfrom
Open
feat(gzip): add option to combine default and custom compression decisions#135kekexiaoai wants to merge 1 commit intogin-contrib:masterfrom
kekexiaoai wants to merge 1 commit intogin-contrib:masterfrom
Conversation
…sions
This patch introduces a new option `WithCombineDefaultAndCustom` to the
gin-contrib/gzip middleware, allowing developers to control how
`customShouldCompressFn` interacts with the default `shouldCompress` logic.
Previously, when a custom compression decision function was provided,
the default compression rules (Accept-Encoding, excluded paths,
excluded extensions, Upgrade connections, etc.) were completely bypassed.
This made it impossible to extend the default behavior without fully
re-implementing it externally.
Changes introduced:
- Add `combineDefaultAndCustom` flag to the gzipHandler config.
- Update compression decision logic:
- When `combineDefaultAndCustom = true`, compression is enabled only if:
customShouldCompressFn(c) && shouldCompress(c.Request)
- When `combineDefaultAndCustom = false` (default behavior),
customShouldCompressFn fully overrides default logic.
- Add new option:
`gzip.WithCombineDefaultAndCustom()`
- Preserve full backward compatibility.
- Update handler logic to use the new combined decision flow.
This enhancement allows developers to:
- Extend default compression behavior safely.
- Add additional custom filters without losing built-in protections.
- Support advanced use cases such as conditionally enabling gzip only
on specific cluster nodes (e.g. leader-only compression) while still
respecting default checks.
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.
…sions
This patch introduces a new option
WithCombineDefaultAndCustomto the gin-contrib/gzip middleware, allowing developers to control howcustomShouldCompressFninteracts with the defaultshouldCompresslogic.Previously, when a custom compression decision function was provided, the default compression rules (Accept-Encoding, excluded paths, excluded extensions, Upgrade connections, etc.) were completely bypassed. This made it impossible to extend the default behavior without fully re-implementing it externally.
Changes introduced:
combineDefaultAndCustomflag to the gzipHandler config.combineDefaultAndCustom = true, compression is enabled only if: customShouldCompressFn(c) && shouldCompress(c.Request)combineDefaultAndCustom = false(default behavior), customShouldCompressFn fully overrides default logic.gzip.WithCombineDefaultAndCustom()This enhancement allows developers to: