Repository navigation
Conversation
respond() echoed the body regardless of the status. RFC 9110 forbids a body for 204 and 304 responses, and strict HTTP/1.1 clients fail to parse such responses (for example a JSON:API body on a 204 DELETE response). respond() now determines the effective status (the Status header if set, as that is what sendHeaders() sends, otherwise the PSR-7 status code) and skips the body for 1xx, 204 and 304, and the default Content-Type for 1xx and 204. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary of Changes
respond()echoes the body regardless of the status. RFC 9110 forbids a body on 204 and 304 responses, and strict HTTP/1.1 clients fail to parse such responses (e.g. a CMS APIDELETEanswering 204 with a JSON:API body, joomla/joomla-cms#48553).This builds on the approach of #155 (and its 3.x twin #156) by @bcordis, with one difference: the status is usually carried in the
Statusheader (setHeader('Status', '204'),redirect()), which is also whatsendHeaders()sends as the status line, while the PSR-7 status code stays 200. Checking onlygetStatusCode(), as #155 does, misses those responses.respond()now determines the effective status (theStatusheader if present, elsegetStatusCode()) andContent-Typefor 1xx and 204; a 304 keeps it, as it describes the representation being validated (RFC 9110 §15.4.5).#161 (keeping the PSR-7 status code in sync with the
Statusheader) touches other lines ofrespond(); the two are independent and should merge without conflict.Testing Instructions
vendor/bin/phpunit --filter testRespond:testRespondWithoutBodycovers 204/304 set on the PSR-7 response and via theStatusheader (output must be empty,Content-Typeonly for 304);testRespondWithBodychecks that a 404 still sends its body. All fourtestRespondWithoutBodycases fail without the change insrc/.Documentation Changes Required
docs/web-application.md("Headers", after theStatusparagraph) and therespond()row indocs/api-reference.md.Supersedes #155
🤖 Generated with Claude Code