Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[HttpClient] Fix processing a NativeResponse after its client has been reset #59631

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 28, 2025

Conversation

Jean-Beru
Copy link
Contributor

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

An exception is thrown in dev when a response is processed before streaming it.

It is due to the HttpClientDataCollector which resets the client between the first access to the response and the next ones. This operation resets the NativeClientState and its hosts property which is used in the NativeReponse when the stream is cancelled or completed.

Reproducer

/** @var NativeHttpClient $appClient **/
$response = $appClient->request('GET', 'https://google.com');

return new StreamedResponse(
    function () use ($appClient, $response): void {
        foreach ($appClient->stream($response) as $chunk) {
            echo $chunk->getContent(); // it fails because this code is executed AFTER collecting data and so, the client reset
            flush();
        }
    },
    $response->getStatusCode(), // the status code is retrieved BEFORE the reset done by the HttpClientDataCollector
);

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.

LGTM but we don't need these extra comments. The issue can happen in other contexts. The name of the test case LGTM.

@nicolas-grekas nicolas-grekas changed the title [HttpClient] Fix "Undefined array key" when processing a NativeResponse [HttpClient] Fix processing a NativeResponse after its client has been reset Jan 28, 2025
@nicolas-grekas
Copy link
Member

Thank you @Jean-Beru.

@nicolas-grekas nicolas-grekas merged commit 7e396bb into symfony:6.4 Jan 28, 2025
11 checks passed
@Jean-Beru Jean-Beru deleted the fix-native-http-client branch January 28, 2025 16:26
This was referenced Jan 29, 2025
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