Skip to content

Conversation

@apoca
Copy link
Contributor

@apoca apoca commented Dec 17, 2025

Q A
Branch? 7.4
Bug fix? yes
New feature? no
Deprecations? no
Issues Fix #62787
License MIT

What does this fix?

Fixes incorrect dumper selection when Accept: */* header is present in HTTP requests, causing dd() and dump() output to disappear in browsers.

The Problem

Since version 7.4.0 (PR #58070), when an HTTP request includes Accept: */* header, the dumper selection logic incorrectly chooses CliDumper instead of HtmlDumper. This causes dumps to be sent to STDOUT instead of being rendered in the browser response.

Affected scenario:

// Browser makes request with Accept: */*
// dd(['test' => 123]) produces blank page instead of showing dump

Common with:

  • AJAX requests without explicit Accept header
  • API clients (Postman, Insomnia)
  • cURL without -H "Accept: text/html"
  • PHP-FPM environments

Root Cause

Current code only checks if Accept contains literal string 'html':

str_contains($_SERVER['HTTP_ACCEPT'], 'html') ? new HtmlDumper() : new CliDumper()

According to RFC 9110 Section 12.5.1, */* means "accept any media type", including text/html.

Solution

Added explicit check for wildcard pattern:

$accept = $_SERVER['HTTP_ACCEPT'] ?? (\in_array(\PHP_SAPI, ['cli', 'phpdbg', 'embed'], true) ? 'txt' : 'html');
$dumper = (str_contains($accept, 'html') || str_contains($accept, '*/*')) ? new HtmlDumper() : new CliDumper();

Before: Accept: */* → ❌ CliDumper (blank page)
After: Accept: */* → ✅ HtmlDumper (dump visible)

Backward Compatibility

✅ Fully backward compatible - only fixes broken behavior introduced in 7.4.0

Test coverage:

  • Accept: text/html → HtmlDumper (unchanged)
  • Accept: */* → HtmlDumper (fixed)
  • Accept: application/json → CliDumper (unchanged)
  • CLI SAPI → CliDumper (unchanged)

@carsonbot
Copy link

Hey!

I see that this is your first PR. That is great! Welcome!

Symfony has a contribution guide which I suggest you to read.

In short:

Review the GitHub status checks of your pull request and try to solve the reported issues. If some tests are failing, try to see if they are failing because of this change.

When two Symfony core team members approve this change, it will be merged and you will become an official Symfony contributor!
If this PR is merged in a lower version branch, it will be merged up to all maintained branches within a few days.

I am going to sit back now and wait for the reviews.

Cheers!

Carsonbot

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

works for me, can you add a test case please?

@nicolas-grekas nicolas-grekas force-pushed the fix-accept-wildcard-dumper branch from 42e3c2e to bc7b547 Compare December 18, 2025 07:04
@nicolas-grekas
Copy link
Member

Thank you @apoca.

@nicolas-grekas nicolas-grekas merged commit c12345d into symfony:7.4 Dec 18, 2025
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants