Skip to content

fix(middleware): honor all-types compress wildcard#1121

Open
happysnaker wants to merge 1 commit into
go-chi:masterfrom
happysnaker:fix-compress-all-wildcard
Open

fix(middleware): honor all-types compress wildcard#1121
happysnaker wants to merge 1 commit into
go-chi:masterfrom
happysnaker:fix-compress-all-wildcard

Conversation

@happysnaker

Copy link
Copy Markdown
Contributor

Summary

  • make NewCompressor(..., "/*") behave as an actual all-types wildcard
  • keep the existing wildcard parsing model and fix only the matching side
  • add regression coverage for both application/* and text/* responses

Problem

NewCompressor(5, "/*") is currently accepted as a valid wildcard pattern, but it silently does not work.

During setup, the pattern is normalized into an empty wildcard key via strings.CutSuffix("/*", "/*"), which is fine as an internal sentinel. The problem is in isCompressible(): wildcard matching only checks the top-level media type prefix (for example text or application) and never treats the empty key as a match-all sentinel.

That means the following configuration looks valid but compresses nothing:

middleware.NewCompressor(5, "/*")

Changes

  • treat an empty wildcard key as "match any top-level media type" during content-type checks
  • add a focused regression test showing that "/*" now compresses both application/json and text/html; charset=utf-8

The patch is intentionally narrow: it does not change the wildcard syntax rules, only makes the already-accepted "/*" form behave consistently.

Closes #868

@happysnaker

Copy link
Copy Markdown
Contributor Author

Maintainer context:

  • this keeps the existing wildcard syntax exactly as-is and only fixes the already-accepted "/*" form on the matching side
  • NewCompressor(..., "/*") already normalizes into an empty wildcard key today, so the narrow intent here is just to make that sentinel behave consistently instead of silently matching nothing
  • I kept the regression coverage focused on real response types (application/json and text/html; charset=utf-8) to show the intended runtime behavior without broadening the wildcard model further

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.

Brotli compression not working

1 participant