From 33ed4e43c4eabcdb51c972a49c35ce6e6c9e69c7 Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Tue, 23 Jul 2019 21:13:48 +0200 Subject: [PATCH] [HttpClient] rewind streams created from strings --- src/Symfony/Component/HttpClient/HttplugClient.php | 8 +++++++- src/Symfony/Component/HttpClient/Psr18Client.php | 8 +++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpClient/HttplugClient.php b/src/Symfony/Component/HttpClient/HttplugClient.php index 6c612ce13c..71eb5200ce 100644 --- a/src/Symfony/Component/HttpClient/HttplugClient.php +++ b/src/Symfony/Component/HttpClient/HttplugClient.php @@ -100,7 +100,13 @@ final class HttplugClient implements HttpClient, RequestFactory, StreamFactory, } if (\is_string($body ?? '')) { - return $this->client->createStream($body ?? ''); + $body = $this->client->createStream($body ?? ''); + + if ($body->isSeekable()) { + $body->seek(0); + } + + return $body; } if (\is_resource($body)) { diff --git a/src/Symfony/Component/HttpClient/Psr18Client.php b/src/Symfony/Component/HttpClient/Psr18Client.php index ee8c813b46..acc85b8ea2 100644 --- a/src/Symfony/Component/HttpClient/Psr18Client.php +++ b/src/Symfony/Component/HttpClient/Psr18Client.php @@ -125,7 +125,13 @@ final class Psr18Client implements ClientInterface, RequestFactoryInterface, Str */ public function createStream(string $content = ''): StreamInterface { - return $this->streamFactory->createStream($content); + $stream = $this->streamFactory->createStream($content); + + if ($stream->isSeekable()) { + $stream->seek(0); + } + + return $stream; } /**