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
When Controller's action method is returning a StreamedResponse like following sample code:
`
public function event(HttpClientInterface $client): StreamedResponse
{
$response = new StreamedResponse();
$response->setCallback(function () use ($client) {
$url = 'https://symfony.com';
$response = $client->request('GET', $url);
});
return $response;
}
`
And the callback method is sending an HTTP request thru the symfony HTTP Client.
The bug: The profiler's Http Client panel is empty.
According our investigation, this is due to the fact that kernel.response event is dispatched (and thus the call to HttpClientDataCollector::collect() method) before HttpClient send the request, so no data are yet collected.
HttpClientDataCollector is already implementing LateDataCollectorInterface but the lateCollect() is only resetting the client object.
…evel (pforesi)
This PR was squashed before being merged into the 5.4 branch.
Discussion
----------
[HttpClient] Move Http clients data collecting at a late level
This allows to collect http clients data when sending them in a StreamedResponse callback method
| Q | A
| ------------- | ---
| Branch? | 5.4
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | Fix#48894
| License | MIT
| Doc PR |
<!--
Replace this notice by a short README for your feature/bugfix.
This will help reviewers and should be a good start for the documentation.
Additionally (see https://symfony.com/releases):
- Always add tests and ensure they pass.
- Bug fixes must be submitted against the lowest maintained branch where they apply
(lowest branches are regularly merged to upper ones so they get the fixes too).
- Features and deprecations must be submitted against the latest branch.
- For new features, provide some code snippets to help understand usage.
- Changelog entry should follow https://symfony.com/doc/current/contributing/code/conventions.html#writing-a-changelog-entry
- Never break backward compatibility (see https://symfony.com/bc).
-->
When a controller action is returning a StreamedResponse doing some HttpClient requests, http clients data are collected to early, so the Web profiler HttpClient panel is wrongly empty.
To fix this we moved data collecting to the HttpClientDataCollector::lateCollect() method which is called on ther kernel.terminate event.
Commits
-------
692a631 [HttpClient] Move Http clients data collecting at a late level
Symfony version(s) affected
4.4.1 (https://github.com/symfony/symfony/blob/0f51da6ec7c3e905fcfebd49e99e0b4a12a3a733/src/Symfony/Component/HttpClient/DataCollector/HttpClientDataCollector.php)
Description
When Controller's action method is returning a StreamedResponse like following sample code:
`
`
And the callback method is sending an HTTP request thru the symfony HTTP Client.
The bug: The profiler's Http Client panel is empty.
According our investigation, this is due to the fact that kernel.response event is dispatched (and thus the call to HttpClientDataCollector::collect() method) before HttpClient send the request, so no data are yet collected.
HttpClientDataCollector is already implementing LateDataCollectorInterface but the lateCollect() is only resetting the client object.
How to reproduce
Possible Solution
Do data collecting into the lateCollect() instead of the collect() method:
`
`
Additional Context
No response
The text was updated successfully, but these errors were encountered: