Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 0c6d64b

Browse filesBrowse files
minor #35034 [HttpClient] In StreamWrapper::createResource use the more efficient Response::toStream method if safe and available (Devristo)
This PR was merged into the 5.1-dev branch. Discussion ---------- [HttpClient] In `StreamWrapper::createResource` use the more efficient `Response::toStream` method if safe and available | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | Deprecations? | no | Tickets | Fix #34834 | License | MIT | Doc PR | symfony/symfony-docs#... <!-- required for new features --> In `StreamWrapper::createResource` use the more efficient `Response::toStream` method if safe and available. Commits ------- e2c2397 [HttpClient] In `StreamWrapper::createResource` use the more efficient `Response::toStream` method if safe and available
2 parents e9f0cfe + e2c2397 commit 0c6d64b
Copy full SHA for 0c6d64b

File tree

1 file changed

+8
-0
lines changed
Filter options

1 file changed

+8
-0
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/Response/StreamWrapper.php
+8Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.