Skip to content

Commit 31e1bf1

Browse files
[HttpClient] fix casting TraceableResponse to php streams
1 parent 00e79c5 commit 31e1bf1

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

Internal/HttplugWaitLoop.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Psr\Http\Message\StreamFactoryInterface;
1818
use Symfony\Component\HttpClient\Response\ResponseTrait;
1919
use Symfony\Component\HttpClient\Response\StreamWrapper;
20+
use Symfony\Component\HttpClient\Response\TraceableResponse;
2021
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
2122
use Symfony\Contracts\HttpClient\HttpClientInterface;
2223
use Symfony\Contracts\HttpClient\ResponseInterface;
@@ -119,7 +120,7 @@ public function createPsr7Response(ResponseInterface $response, bool $buffer = f
119120
}
120121
}
121122

122-
if (isset(class_uses($response)[ResponseTrait::class])) {
123+
if ($response instanceof TraceableResponse || isset(class_uses($response)[ResponseTrait::class])) {
123124
$body = $this->streamFactory->createStreamFromResource($response->toStream(false));
124125
} elseif (!$buffer) {
125126
$body = $this->streamFactory->createStreamFromResource(StreamWrapper::createResource($response, $this->client));

Psr18Client.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use Psr\Http\Message\UriInterface;
3030
use Symfony\Component\HttpClient\Response\ResponseTrait;
3131
use Symfony\Component\HttpClient\Response\StreamWrapper;
32+
use Symfony\Component\HttpClient\Response\TraceableResponse;
3233
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
3334
use Symfony\Contracts\HttpClient\HttpClientInterface;
3435

@@ -104,7 +105,7 @@ public function sendRequest(RequestInterface $request): ResponseInterface
104105
}
105106
}
106107

107-
$body = isset(class_uses($response)[ResponseTrait::class]) ? $response->toStream(false) : StreamWrapper::createResource($response, $this->client);
108+
$body = $response instanceof TraceableResponse || isset(class_uses($response)[ResponseTrait::class]) ? $response->toStream(false) : StreamWrapper::createResource($response, $this->client);
108109
$body = $this->streamFactory->createStreamFromResource($body);
109110

110111
if ($body->isSeekable()) {

Response/StreamWrapper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class StreamWrapper
4949
*/
5050
public static function createResource(ResponseInterface $response, HttpClientInterface $client = null)
5151
{
52-
if (\is_callable([$response, 'toStream']) && isset(class_uses($response)[ResponseTrait::class])) {
52+
if ($response instanceof TraceableResponse || (\is_callable([$response, 'toStream']) && isset(class_uses($response)[ResponseTrait::class]))) {
5353
$stack = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS, 2);
5454

5555
if ($response !== ($stack[1]['object'] ?? null)) {

0 commit comments

Comments
 (0)