Skip to content

Conversation

@wuchen90
Copy link
Contributor

Q A
Branch? 7.3
Bug fix? yes
New feature? no
Deprecations? no
License MIT

This PR fixes changes done in #60262 that breaks HttpKernelBrowser when it comes to deal with StreamedResponse created with an iterator.

Spomky
Spomky previously approved these changes Nov 3, 2025
Copy link
Contributor

@Spomky Spomky left a comment

Choose a reason for hiding this comment

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

Looks good to me.
I revised my mind because the failing tests are due to this PR.

  • The ob_start callback shall return a string but here nothing is returned.
  • Also, in case of an exception the buffer is still open.

The current behavious is not perfect because of the last bullet.
A possible solution:

    $content = '';
    ob_start(static function (string $chunk, int $phase): string {
        return $chunk;
    });

    try {
        $response->sendContent();
        $buffered = ob_get_contents();
    } finally {
        ob_end_clean();
    }
    $final = $buffered !== false ? $buffered : $content;

@mtarld any thoughts on this PR?

@Spomky Spomky self-requested a review November 3, 2025 13:39
@wuchen90 wuchen90 force-pushed the fix-http-kernel-browser branch 2 times, most recently from d9ab24c to 7bfcc2c Compare November 3, 2025 16:30
@Spomky Spomky dismissed their stale review November 6, 2025 20:46

Changed my mind

@nicolas-grekas nicolas-grekas force-pushed the fix-http-kernel-browser branch from fd8fb64 to 2932941 Compare November 12, 2025 17:28
@nicolas-grekas
Copy link
Member

Thank you @wuchen90.

@nicolas-grekas nicolas-grekas merged commit 92f9979 into symfony:7.3 Nov 12, 2025
10 of 11 checks passed
@wuchen90 wuchen90 deleted the fix-http-kernel-browser branch November 13, 2025 08:05
@Spomky
Copy link
Contributor

Spomky commented Nov 13, 2025

Hi @nicolas-grekas,

As mentioned in #62036 (review), ob_start callback is expected to return a string.
In this PR, the callback only concatenates the chunk with the buffer.
Is there any impact in not returning a string?

@nicolas-grekas
Copy link
Member

I fixed this concern in bfe4671
It was fine until PHP 8.5 to return nothing. Now, we should return the empty string, not the buffer.

@Spomky
Copy link
Contributor

Spomky commented Nov 13, 2025

I missed it. Thank you for the clarification.

@fabpot fabpot mentioned this pull request Nov 13, 2025
@fabpot fabpot mentioned this pull request Nov 13, 2025
@fabpot fabpot mentioned this pull request Dec 7, 2025
@BafS
Copy link
Contributor

BafS commented Dec 10, 2025

This change broke our tests, we loosely have a test like that

ob_start();
$client->request('GET', "/photos/$slug");
$content = ob_get_clean();

With this refactor the $content is empty. I don't know if the iterator should be rewinded.

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.

5 participants