Skip to content

fix(index): preserve global option fields when route options are partial#398

Closed
ranjeetcao wants to merge 1 commit into
fastify:mainfrom
ranjeetcao:fix/340-merge-route-options-with-globals
Closed

fix(index): preserve global option fields when route options are partial#398
ranjeetcao wants to merge 1 commit into
fastify:mainfrom
ranjeetcao:fix/340-merge-route-options-with-globals

Conversation

@ranjeetcao

@ranjeetcao ranjeetcao commented May 17, 2026

Copy link
Copy Markdown

Calling Object.assign({}, global, processCompressParams(partialRoute)) copies undefined values from the post-processed route object onto the global params, silently nulling out fields like onInvalidRequestPayload, onUnsupportedRequestEncoding, and onUnsupportedEncoding whenever the route configures only one of them.

Fix the merge order: combine the raw user opts with the raw route opts first, then pass the result through processCompressParams / processDecompressParams once so each derived field is computed from a coherent input rather than shallow-merged from already-processed objects.

Adds unit tests covering both decompress hook fallbacks and the compress onUnsupportedEncoding fallback.

Closes #340

Checklist

Calling `Object.assign({}, global, processCompressParams(partialRoute))`
copies undefined values from the post-processed route object onto the
global params, silently nulling out fields like `onInvalidRequestPayload`,
`onUnsupportedRequestEncoding`, and `onUnsupportedEncoding` whenever
the route configures only one of them.

Fix the merge order: combine the raw user opts with the raw route opts
first, then pass the result through `processCompressParams` /
`processDecompressParams` once so each derived field is computed from a
coherent input rather than shallow-merged from already-processed objects.

Adds unit tests covering both decompress hook fallbacks and the
compress `onUnsupportedEncoding` fallback.

Closes fastify#340
@ranjeetcao

Copy link
Copy Markdown
Author

Closing as a duplicate of #397 (opened May 11, 6 days before mine — I missed it when scanning the issue). Apologies for the noise.
I'll flag one delta on #397 that might be worth picking up: my branch adds a test for the compress-side onUnsupportedEncoding fallback (the regression covered all three of onInvalidRequestPayload, onUnsupportedRequestEncoding, and onUnsupportedEncoding, but #397's test coverage only touches the first two). Happy to send a follow-up test PR if #397 lands as-is. Test is here for reference: https://github.com/fastify/fastify-compress/pull/398/changes#diff-e13c4cd5dbfbf47dd973a06293644d67cd529850c7d6df9ab4ff12563335536cR474

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.

global options are not taked into account when route options are defined partially

1 participant