Skip to content

fix: forward encode option to cookie serializer - #374

Open
lprnmns wants to merge 1 commit into
fastify:mainfrom
lprnmns:fix/forward-cookie-encode-option-human-dco
Open

lprnmns wants to merge 1 commit into
fastify:mainfrom
lprnmns:fix/forward-cookie-encode-option-human-dco

Conversation

@lprnmns

@lprnmns lprnmns commented Aug 31, 2026

Copy link
Copy Markdown

Problem

After the cookie@2 migration, a custom encode function passed to reply.setCookie() or the serializer decorator is ignored. The resulting Set-Cookie value is emitted without the caller's encoder, despite encode being a documented cookie serialization option.

Fix

Forward the existing options object as cookie@2's serializer-options argument so its encode function is applied. Calls without encode retain their current output.

Tests

  • node --test --test-name-pattern='passes encode option to cookie serializer' test/cookie.test.js — passed after the fix; the same test failed before the fix with foo=bar instead of foo=encoded.
  • npm test — passed; 54 unit tests and 46 type assertions.
  • npm run lint — passed.
  • npm run test && npm run benchmark --if-present — passed; no benchmark script is defined.
  • node --check index.js && node --check test/cookie.test.js — passed.
  • git diff --check — passed.

Compatibility

The public API signature is unchanged. Existing calls without a custom encoder produce the same serialization; calls with encode now honor the documented option. The change adds no dependency or lockfile updates.

Related issue

Independent reproduction. No currently open issue or competing pull request for this behavior was found.

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 2, 2026 07:33

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.

🟢 Approval recommended

The focused fix correctly restores documented encoding behavior with regression coverage.

Pull request overview

Fixes custom cookie encoders by forwarding serialization options to cookie@2.

Changes:

  • Passes options to stringifySetCookie.
  • Adds regression coverage for reply.setCookie() encoding.
File summaries
File Description
index.js Forwards serializer options.
test/cookie.test.js Verifies custom encoding.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Balanced

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

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