fix: merge partial route options with global options - #397
Conversation
0487e7a to
64e54e5
Compare
|
👋 I just closed #398 in favor of this one (it hadn't surfaced in my issue-thread search). One small suggestion if you take another pass: this regression also affects the compress-side onUnsupportedEncoding hook (not just the decompress hooks), and the current test coverage here doesn't exercise that path. A minimal test sketch: Full version on my closed PR if useful: https://github.com/fastify/fastify-compress/pull/398/files |
|
Thanks for catching this, @ranjeetcao. That path was a real coverage gap. I added a focused regression test for the route-level I also re-ran:
Appreciate the pointer. |
There was a problem hiding this comment.
Pull request overview
This PR fixes option resolution precedence so that partial route-level compress/decompress option objects inherit from processed global plugin options first, and only fall back to plugin defaults when neither route nor global provided a value (fixing #340).
Changes:
- Refactored option processing to support
process*Params(routeOpts, globalParams)merging without re-expanding missing route values to plugin defaults. - Added regression tests to ensure partial route overrides preserve global handlers/settings (
onInvalidRequestPayload,removeContentLengthHeader: false).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
index.js |
Refactors compress/decompress parameter processing to properly merge route-level partial options with processed global options. |
test/routes-decompress.test.js |
Adds coverage ensuring a partial route decompress override preserves the global onInvalidRequestPayload handler. |
test/routes-compress.test.js |
Adds coverage ensuring a partial route compress override preserves global removeContentLengthHeader: false (and adds a related partial-options test). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.
Suppressed comments (1)
index.js:262
baseParams.encodingsmay already have been narrowed to the globalforceRequestEncodingbelow. Consequently, with global{ requestEncodings: ['gzip', 'deflate'], forceRequestEncoding: 'gzip' }, a route override{ forceRequestEncoding: 'deflate' }inherits only['gzip']and rejects every request, althoughdeflateis allowed by the global list. Preserve the unforced request-encoding list separately and narrow only the effective route list after resolving its force option; this case should also have regression coverage.
encodings: encodingsOrBase(opts, 'requestEncodings', baseParams),
forceEncoding: forceEncodingOrBase(opts, baseParams)
}
if (params.forceEncoding && params.encodings.includes(params.forceEncoding)) {
params.encodings = [params.forceEncoding]
4ba2e6d to
4155222
Compare
|
Thanks @Fdawgs — I simplified the implementation to follow the approach in #398: raw global and route options are merged first, then passed through the existing processor once. The processor refactor and merge commit are gone, and the branch is rebased onto current I also trimmed the tests to the minimum focused coverage: the issue #340 invalid-payload-handler case, compression-handler inheritance, Local validation:
The fresh GitHub Actions run is currently marked |
Signed-off-by: Vinayak <34209962+Vinayak1337@users.noreply.github.com>
4155222 to
99df941
Compare
Fixes #340
What changed
compressanddecompressoptions before processing them once.forceRequestEncodingscenario raised during review.Why
The previous
Object.assign({}, globalParams, processParams(routeOptions))flow allowed defaults andundefinedfields from the processed route object to overwrite configured global values. Processing one coherent{ ...globalOptions, ...routeOptions }object applies the intended route > global > default precedence and follows the simpler approach demonstrated in #398.Tests
node --test test/routes-compress.test.js test/routes-decompress.test.jsnpm run lintnpm testgit diff --checknpm run benchmark --if-present(executed; the harness rejected the measurements because the unchanged control varied by 12% on a busy machine)No documentation or type changes are needed because this fixes existing option precedence without changing the public API.
Checklist
npm run test && npm run benchmark --if-present