Commit 7e396bb
committed
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 resetFile tree
2 files changed
+19
-6
lines changed- src/Symfony/Component/HttpClient
- Response
- Tests
2 files changed
+19
-6
lines changedLines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
83 | 83 | | |
84 | 84 | | |
85 | 85 | | |
| |||
123 | 123 | | |
124 | 124 | | |
125 | 125 | | |
126 | | - | |
| 126 | + | |
127 | 127 | | |
128 | 128 | | |
129 | 129 | | |
| |||
142 | 142 | | |
143 | 143 | | |
144 | 144 | | |
145 | | - | |
| 145 | + | |
146 | 146 | | |
147 | 147 | | |
148 | 148 | | |
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
162 | | - | |
| 162 | + | |
163 | 163 | | |
164 | 164 | | |
165 | 165 | | |
| |||
294 | 294 | | |
295 | 295 | | |
296 | 296 | | |
297 | | - | |
| 297 | + | |
298 | 298 | | |
299 | 299 | | |
300 | 300 | | |
301 | 301 | | |
302 | 302 | | |
303 | 303 | | |
304 | 304 | | |
305 | | - | |
| 305 | + | |
306 | 306 | | |
307 | 307 | | |
308 | 308 | | |
| |||
Lines changed: 13 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
695 | 695 | | |
696 | 696 | | |
697 | 697 | | |
| 698 | + | |
| 699 | + | |
| 700 | + | |
| 701 | + | |
| 702 | + | |
| 703 | + | |
| 704 | + | |
| 705 | + | |
| 706 | + | |
| 707 | + | |
| 708 | + | |
| 709 | + | |
| 710 | + | |
698 | 711 | | |
0 commit comments