You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
bug symfony#59631 [HttpClient] Fix processing a NativeResponse after its client has been reset (Jean-Beru)
This PR was merged into the 6.4 branch.
Discussion
----------
[HttpClient] Fix processing a NativeResponse after its client has been reset
| 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](https://github.com/symfony/symfony/blob/6.4/src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php#L41) 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
```php
/** `@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
);
```
Commits
-------
0a4521e [HttpClient] Fix processing a NativeResponse after its client has been reset
0 commit comments