Skip to content

fix(middleware): match gzip Content-Encoding case-insensitively#3056

Merged
aldas merged 2 commits into
labstack:masterfrom
sonnemusk:fix/decompress-case-insensitive-encoding
Jul 23, 2026
Merged

fix(middleware): match gzip Content-Encoding case-insensitively#3056
aldas merged 2 commits into
labstack:masterfrom
sonnemusk:fix/decompress-case-insensitive-encoding

Conversation

@sonnemusk

Copy link
Copy Markdown
Contributor

Summary

Decompress middleware only accepted exact Content-Encoding: gzip. Values like Gzip or GZIP were skipped.

Change

  • Compare with strings.EqualFold after trim.
  • Add regression tests for common case variants.

Test plan

  • go test ./middleware -run TestDecompress

Proxies and clients may send Content-Encoding: Gzip or GZIP. Exact string
compare skipped decompression. Trim and EqualFold against "gzip".
@aldas

aldas commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

I am not agains this change but please give us real world example then gzip has spaces or different case. are we dealing theoretical problem, fix for some custom client or some widespread problem

@sonnemusk

Copy link
Copy Markdown
Contributor Author

This is primarily RFC compliance, not a custom client quirk.

RFC 9110 §8.4.1 (and earlier HTTP RFCs) define content codings as case-insensitive. So Content-Encoding: Gzip / GZIP are valid and should decompress the same as gzip.

Real-world sources of non-lowercase values:

  • Some language HTTP clients / libraries canonicalize header names but leave coding tokens as the caller typed them.
  • Reverse proxies and gateways that rewrite or re-emit Content-Encoding without lowercasing.
  • Integration tests and generated clients often send Gzip.

The TrimSpace part is minor (malformed-but-common whitespace); the important bit is EqualFold for case-insensitivity required by the HTTP semantics. Happy to drop the trim if you only want the case fix.

Drop TrimSpace so the change is strictly RFC 9110 case-insensitivity
for content codings, per review discussion.
@sonnemusk

Copy link
Copy Markdown
Contributor Author

Follow-up: I dropped the TrimSpace part so this PR is only case-insensitivity via strings.EqualFold, matching RFC 9110 content-coding rules.

Concrete cases this fixes:

  • clients/libraries that send Content-Encoding: Gzip or GZIP (valid per HTTP; previously skipped decompression and left a gzip body for handlers to read as plain text)
  • e.g. some Java/OkHttp and generated clients historically emit mixed-case coding tokens

Happy to adjust further if you want a different approach.

@sonnemusk
sonnemusk force-pushed the fix/decompress-case-insensitive-encoding branch from c4b0fdd to c7d2c83 Compare July 22, 2026 07:56
@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.35%. Comparing base (dcb05f0) to head (c7d2c83).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3056   +/-   ##
=======================================
  Coverage   93.34%   93.35%           
=======================================
  Files          43       43           
  Lines        4735     4737    +2     
=======================================
+ Hits         4420     4422    +2     
  Misses        192      192           
  Partials      123      123           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aldas aldas left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@aldas
aldas merged commit 79b4968 into labstack:master Jul 23, 2026
10 checks passed
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