8000 [HttpClient] In `StreamWrapper::createResource` use the more efficien… · symfony/symfony@e2c2397 · GitHub
[go: up one dir, main page]

Skip to content

Commit e2c2397

Browse files
Devristonicolas-grekas
authored andcommitted
[HttpClient] In StreamWrapper::createResource use the more efficient Response::toStream method if safe and available
1 parent e9f0cfe commit e2c2397

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

src/Symfony/Component/HttpClient/Response/StreamWrapper.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,14 @@ class StreamWrapper
4949
*/
5050
public static function createResource(ResponseInterface $response, HttpClientInterface $client = null)
5151
{
52+
if (null === $client && \is_callable([$response, 'toStream']) && isset(class_uses($response)[ResponseTrait::class])) {
53+
$stack = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS, 2);
54+
55+
if ($response !== ($stack[1]['object'] ?? null)) {
56+
return $response->toStream(false);
57+
}
58+
}
59+
5260
if (null === $client && !method_exists($response, 'stream')) {
5361
throw new \InvalidArgumentException(sprintf('Providing a client to "%s()" is required when the response doesn\'t have any "stream()" method.', __CLASS__));
5462
}

0 commit comments

Comments
 (0)
0