Skip to content

fix: negotiate encoding before compression checks - #425

Open
pratik-desgn wants to merge 1 commit into
fastify:mainfrom
pratik-desgn:fix-unsupported-encoding-short-circuit
Open

fix: negotiate encoding before compression checks#425
pratik-desgn wants to merge 1 commit into
fastify:mainfrom
pratik-desgn:fix-unsupported-encoding-short-circuit

Conversation

@pratik-desgn

@pratik-desgn pratik-desgn commented Aug 10, 2026

Copy link
Copy Markdown

Fixes #305.

The compression paths currently negotiate Accept-Encoding inside the last operand of a short-circuiting noCompress expression. When x-no-compression or a non-compressible content type matches first, encoding remains undefined and a configured onUnsupportedEncoding handler is called even for a supported encoding.

This change negotiates the encoding before evaluating the skip conditions in both the global onSend hook and reply.compress() paths. It adds regression coverage for each path and verifies that the response is passed through without invoking the unsupported-encoding handler.

This supersedes the voluntarily closed draft #404 and is rebased on current main.

Validation:

  • npm run lint
  • npm test — 236 unit tests and 10 type assertions passed
  • git diff --check
  • npm run benchmark --if-present completed all measurements, but its unchanged 8 KiB streaming control varied by 25% and exceeded the 10% noise tolerance; the benchmark reports this as machine noise and recommends rerunning on an idle machine before drawing conclusions

Checklist

Signed-off-by: Pratik Dulal <pratikdulal0@gmail.com>
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.

buildRoute(De)Compress doesn't handle non-compressible content if a custom onUnsupported handler is defined

1 participant