From 5733289278b9ee5fac335b40ecc7cbca564a8b4f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Sun, 28 Jun 2020 16:07:40 +0200 Subject: [PATCH] [HttpClient] fix casting TraceableResponse to php streams --- src/Symfony/Component/HttpClient/Internal/HttplugWaitLoop.php | 3 ++- src/Symfony/Component/HttpClient/Psr18Client.php | 3 ++- src/Symfony/Component/HttpClient/Response/StreamWrapper.php | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Symfony/Component/HttpClient/Internal/HttplugWaitLoop.php b/src/Symfony/Component/HttpClient/Internal/HttplugWaitLoop.php index f17a4a78503c3..786b8c0608283 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\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 @@ public function createPsr7Response(ResponseInterface $response, bool $buffer = f } } - 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 67c2fdb8f07bc..b693e015d0295 100644 --- a/src/Symfony/Component/HttpClient/Psr18Client.php +++ b/src/Symfony/Component/HttpClient/Psr18Client.php @@ -29,6 +29,7 @@ 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 @@ public function sendRequest(RequestInterface $request): ResponseInterface } } - $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 0755c2287648c..087445d6e2d87 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)) {