Skip to content

fix: try every encoding in a root before falling back to the next root - #629

Merged
Tony133 merged 2 commits into
fastify:mainfrom
RaphaelFakhri:fix/precompressed-multi-root-fallback
Nov 4, 2026
Merged

Tony133 merged 2 commits into
fastify:mainfrom
RaphaelFakhri:fix/precompressed-multi-root-fallback

Conversation

@RaphaelFakhri

Copy link
Copy Markdown
Contributor

With preCompressed: true and an array root, a file that exists only in the first root without a pre-compressed variant returns 404 when the request sends Accept-Encoding.

On ENOENT, the handler moved to the next root before it tried the remaining encodings in the current root, so the encoding fallback, including the uncompressed file, ran only in the last root.

This change tries the remaining encodings and then the uncompressed file in the current root before it moves to the next root. An earlier root still wins over a later one, which matches the behavior without preCompressed. It also drops the extra identity lookup that the previous checkedEncodings.has(undefined) check caused.

Fixes #628

Checklist

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@Tony133 Tony133 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@Tony133
Tony133 merged commit 44b5a14 into fastify:main Nov 4, 2026
17 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.

preCompressed with multiple roots returns 404 for uncompressed files in the first root

3 participants