Skip to content

fix: accept mixed-case Content-Encoding values - #428

Open
lprnmns wants to merge 2 commits into
fastify:mainfrom
lprnmns:fix/case-insensitive-content-encoding
Open

lprnmns wants to merge 2 commits into
fastify:mainfrom
lprnmns:fix/case-insensitive-content-encoding

Conversation

@lprnmns

@lprnmns lprnmns commented Aug 31, 2026

Copy link
Copy Markdown

Problem

HTTP content-coding names are case-insensitive, but request decompression currently compares the Content-Encoding value exactly. A client sending a valid mixed-case value such as Content-Encoding: GzIp receives a 415 response instead of having its gzip payload decompressed.

Fix

Normalize the request Content-Encoding value to lowercase before checking the configured supported encodings. The change is limited to the request decompression hook and adds regression coverage for mixed-case gzip.

Tests

  • npm run test:unit -- test/global-decompress.test.js — passed (18 tests)
  • npm run lint — passed
  • npm test — passed (235 unit tests and 10 TypeScript assertions)
  • npm run benchmark --if-present — passed; benchmark control stayed within the 10% tolerance
  • git diff --check — passed

Compatibility

Lower-case request headers and forced request encodings keep their existing behavior. Only string Content-Encoding header matching is normalized; no public API or dependency changes are made.

Related issue

No current issue or pull request was found for mixed-case request Content-Encoding handling. This is an independent reproduction of the protocol case-sensitivity defect; it is distinct from open PR #425, which addresses response Accept-Encoding negotiation for issue #305.

Checklist

Signed-off-by: lprnmns <manasalperen@gmail.com>
@lprnmns
lprnmns marked this pull request as ready for review August 31, 2026 16:18
@Fdawgs
Fdawgs requested a balanced review from Copilot September 1, 2026 10:27

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

Normalizes request Content-Encoding values for case-insensitive decompression matching.

Changes:

  • Lowercases string encoding headers before lookup.
  • Adds mixed-case gzip regression coverage.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
index.js Normalizes request encoding values.
test/global-decompress.test.js Tests mixed-case gzip handling.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread index.js
Comment on lines +435 to +437
if (typeof encoding === 'string') {
encoding = encoding.toLowerCase()
}

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good catch. Fixed in bb726a3: matching still uses the normalized value, while the callback and default error receive the original header value. The existing callback test now covers a mixed-case unsupported token; npm test and lint pass.

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