bug #37440 [HttpClient] fix casting TraceableResponse to php streams (nicolas-grekas)
This PR was merged into the 5.1 branch.
Discussion
----------
[HttpClient] fix casting TraceableResponse to php streams
| Q | A
| ------------- | ---
| Branch? | 5.1
| Bug fix? | yes
| New feature? | no
| Deprecations? | no
| Tickets | Fix #37393
| License | MIT
| Doc PR | -
We'd better replace these checks by an `instanceof` one, but that'd be for master.
Commits
-------
5733289278
[HttpClient] fix casting TraceableResponse to php streams
This commit is contained in:
commit
009961795b
@ -17,6 +17,7 @@ use Psr\Http\Message\ResponseInterface as Psr7ResponseInterface;
|
|||||||
use Psr\Http\Message\StreamFactoryInterface;
|
use Psr\Http\Message\StreamFactoryInterface;
|
||||||
use Symfony\Component\HttpClient\Response\ResponseTrait;
|
use Symfony\Component\HttpClient\Response\ResponseTrait;
|
||||||
use Symfony\Component\HttpClient\Response\StreamWrapper;
|
use Symfony\Component\HttpClient\Response\StreamWrapper;
|
||||||
|
use Symfony\Component\HttpClient\Response\TraceableResponse;
|
||||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||||
use Symfony\Contracts\HttpClient\ResponseInterface;
|
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));
|
$body = $this->streamFactory->createStreamFromResource($response->toStream(false));
|
||||||
} elseif (!$buffer) {
|
} elseif (!$buffer) {
|
||||||
$body = $this->streamFactory->createStreamFromResource(StreamWrapper::createResource($response, $this->client));
|
$body = $this->streamFactory->createStreamFromResource(StreamWrapper::createResource($response, $this->client));
|
||||||
|
@ -29,6 +29,7 @@ use Psr\Http\Message\UriFactoryInterface;
|
|||||||
use Psr\Http\Message\UriInterface;
|
use Psr\Http\Message\UriInterface;
|
||||||
use Symfony\Component\HttpClient\Response\ResponseTrait;
|
use Symfony\Component\HttpClient\Response\ResponseTrait;
|
||||||
use Symfony\Component\HttpClient\Response\StreamWrapper;
|
use Symfony\Component\HttpClient\Response\StreamWrapper;
|
||||||
|
use Symfony\Component\HttpClient\Response\TraceableResponse;
|
||||||
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
|
||||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
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);
|
$body = $this->streamFactory->createStreamFromResource($body);
|
||||||
|
|
||||||
if ($body->isSeekable()) {
|
if ($body->isSeekable()) {
|
||||||
|
@ -49,7 +49,7 @@ class StreamWrapper
|
|||||||
*/
|
*/
|
||||||
public static function createResource(ResponseInterface $response, HttpClientInterface $client = null)
|
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);
|
$stack = debug_backtrace(DEBUG_BACKTRACE_PROVIDE_OBJECT | DEBUG_BACKTRACE_IGNORE_ARGS, 2);
|
||||||
|
|
||||||
if ($response !== ($stack[1]['object'] ?? null)) {
|
if ($response !== ($stack[1]['object'] ?? null)) {
|
||||||
|
Reference in New Issue
Block a user