diff --git a/src/Symfony/Component/HttpClient/Internal/HttplugWaitLoop.php b/src/Symfony/Component/HttpClient/Internal/HttplugWaitLoop.php index f17a4a7850..786b8c0608 100644 --- a/src/Symfony/Component/HttpClient/Internal/HttplugWaitLoop.php +++ b/src/Symfony/Component/HttpClient/Internal/HttplugWaitLoop.php @@ -17,6 +17,7 @@ use Psr\Http\Message\ResponseInterface as Psr7ResponseInterface; use Psr\Http\Message\StreamFactoryInterface; use Symfony\Component\HttpClient\Response\ResponseTrait; use Symfony\Component\HttpClient\Response\StreamWrapper; +use Symfony\Component\HttpClient\Response\TraceableResponse; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; use Symfony\Contracts\HttpClient\ResponseInterface; @@ -119,7 +120,7 @@ final class HttplugWaitLoop } } - if (isset(class_uses($response)[ResponseTrait::class])) { + if ($response instanceof TraceableResponse || isset(class_uses($response)[ResponseTrait::class])) { $body = $this->streamFactory->createStreamFromResource($response->toStream(false)); } elseif (!$buffer) { $body = $this->streamFactory->createStreamFromResource(StreamWrapper::createResource($response, $this->client)); diff --git a/src/Symfony/Component/HttpClient/Psr18Client.php b/src/Symfony/Component/HttpClient/Psr18Client.php index 67c2fdb8f0..b693e015d0 100644 --- a/src/Symfony/Component/HttpClient/Psr18Client.php +++ b/src/Symfony/Component/HttpClient/Psr18Client.php @@ -29,6 +29,7 @@ use Psr\Http\Message\UriFactoryInterface; use Psr\Http\Message\UriInterface; use Symfony\Component\HttpClient\Response\ResponseTrait; use Symfony\Component\HttpClient\Response\StreamWrapper; +use Symfony\Component\HttpClient\Response\TraceableResponse; use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface; use Symfony\Contracts\HttpClient\HttpClientInterface; @@ -104,7 +105,7 @@ final class Psr18Client implements ClientInterface, RequestFactoryInterface, Str } } - $body = isset(class_uses($response)[ResponseTrait::class]) ? $response->toStream(false) : StreamWrapper::createResource($response, $this->client); + $body = $response instanceof TraceableResponse || isset(class_uses($response)[ResponseTrait::class]) ? $response->toStream(false) : StreamWrapper::createResource($response, $this->client); $body = $this->streamFactory->createStreamFromResource($body); if ($body->isSeekable()) { diff --git a/src/Symfony/Component/HttpClient/Response/StreamWrapper.php b/src/Symfony/Component/HttpClient/Response/StreamWrapper.php index 0755c22876..087445d6e2 100644 --- a/src/Symfony/Component/HttpClient/Response/StreamWrapper.php +++ b/src/Symfony/Component/HttpClient/Response/StreamWrapper.php @@ -49,7 +49,7 @@ class StreamWrapper */ public static function createResource(ResponseInterface $response, HttpClientInterface $client = null) { - if (\is_callable([$response, 'toStream']) && isset(class_uses($response)[ResponseTrait::class])) { + if ($response instanceof TraceableResponse || (\is_callable([$response, 'toStream']) && isset(class_uses($response)[ResponseTrait::class]))) { $stack = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS, 2); if ($response !== ($stack[1]['object'] ?? null)) {