Skip to content

[4.x] Do not send a body for 1xx, 204 and 304 responses - #165

Open
Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-no-body-for-204-304
Open

Hackwar wants to merge 1 commit into
joomla-framework:4.x-devfrom
Hackwar:4.x-no-body-for-204-304

Conversation

@Hackwar

@Hackwar Hackwar commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

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 API DELETE answering 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 Status header (setHeader('Status', '204'), redirect()), which is also what sendHeaders() sends as the status line, while the PSR-7 status code stays 200. Checking only getStatusCode(), as #155 does, misses those responses. respond() now determines the effective status (the Status header if present, else getStatusCode()) and

  • skips the body for 1xx, 204 and 304,
  • skips the default Content-Type for 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 Status header) touches other lines of respond(); the two are independent and should merge without conflict.

Testing Instructions

vendor/bin/phpunit --filter testRespond: testRespondWithoutBody covers 204/304 set on the PSR-7 response and via the Status header (output must be empty, Content-Type only for 304); testRespondWithBody checks that a 404 still sends its body. All four testRespondWithoutBody cases fail without the change in src/.

Documentation Changes Required

docs/web-application.md ("Headers", after the Status paragraph) and the respond() row in docs/api-reference.md.

Supersedes #155

🤖 Generated with Claude Code

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>
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