Skip to content

[4.x] Send every value of multi-value headers in sendHeaders() - #164

Open
Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-send-all-header-values
Open

Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-send-all-header-values

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Summary of Changes

setHeader($name, $value, false) correctly adds a second value to the PSR-7 response, and getHeaders() returns one entry per value, but sendHeaders() calls header() with the default replace = true for every entry. Each value therefore replaces the previous one and only the last is sent: two Link, Vary or Set-Cookie values end up as one. The $replace = false contract of setHeader() had no effect on the wire (the documented Set-Cookie: a=1 / b=2 example only sent b=2).

sendHeaders() now passes replace = true for the first value of a header name (so a header PHP already queued is still replaced, as before) and replace = false for the following values. The status line handling is unchanged.

This is an alternative to #103, which changes setHeader() semantics instead; setHeader() already behaves correctly, the problem is only in sendHeaders().

Testing Instructions

testSendHeadersWithMultipleValues sets two Link values plus Vary and Set-Cookie and checks the header() calls. It fails without the change in src/; the existing testSendHeaders and redirect tests are unchanged.

Documentation Changes Required

docs/web-application.md ("Headers") now says how sendHeaders() sends multiple values.

Alternative to #103

🤖 Generated with Claude Code

setHeader($name, $value, false) adds a second value to the response and
getHeaders() returns one entry per value, but sendHeaders() called
header() with replace=true for each entry, so every value replaced the
previous one and only the last was sent (two Link, Vary or Set-Cookie
values, for example).

The first value of a name still replaces a header PHP may already have
queued; the following values are now sent with replace=false.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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