Skip to content

fix(fastify): append headers instead of overwriting - #17566

Open
bun-unsafe wants to merge 1 commit into
nestjs:masterfrom
bun-unsafe:fix/fastify-append-header
Open

fix(fastify): append headers instead of overwriting#17566
bun-unsafe wants to merge 1 commit into
nestjs:masterfrom
bun-unsafe:fix/fastify-append-header

Conversation

@bun-unsafe

Copy link
Copy Markdown

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

AbstractHttpAdapter.appendHeader / ExpressAdapter.appendHeader append a header value (response.append). FastifyAdapter.appendHeader calls Fastify reply.header(), which replaces any existing value except for set-cookie.

Calling appendHeader twice with the same name (for example x-a: 1 then x-a: 2) therefore keeps only the last value on Fastify, while Express keeps both.

This dates back to the original adapter methods in #12955.

Issue Number: N/A

What is the new behavior?

FastifyAdapter.appendHeader concatenates onto the current header when one is already set, matching Express.

set-cookie still goes through Fastify reply.header() only. Fastify already concatenates that name; passing the accumulated list back into header() would duplicate previous cookies.

Does this PR introduce a breaking change?

  • Yes
  • No

Call sites that used appendHeader as a second setHeader on Fastify would start seeing multiple values. That matches the method name and ExpressAdapter.

Other information

Repro: Fastify adapter, appendHeader(res, 'x-a', '1') then appendHeader(res, 'x-a', '2'), then getHeader(res, 'x-a'). Before: '2'. After: ['1', '2'].

Tests: packages/platform-fastify/test/adapters/fastify-adapter.spec.ts (append twice, setHeader then append, header name case, three values, set-cookie without duplicates).

npx vitest run packages/platform-fastify/test/adapters/fastify-adapter.spec.ts

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.

1 participant