[HttpClient] rewind streams created from strings

This commit is contained in:
Nicolas Grekas 2019-07-23 21:13:48 +02:00
parent 759f91c565
commit 33ed4e43c4
2 changed files with 14 additions and 2 deletions

View File

@ -100,7 +100,13 @@ final class HttplugClient implements HttpClient, RequestFactory, StreamFactory,
} }
if (\is_string($body ?? '')) { 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)) { if (\is_resource($body)) {

View File

@ -125,7 +125,13 @@ final class Psr18Client implements ClientInterface, RequestFactoryInterface, Str
*/ */
public function createStream(string $content = ''): StreamInterface public function createStream(string $content = ''): StreamInterface
{ {
return $this->streamFactory->createStream($content); $stream = $this->streamFactory->createStream($content);
if ($stream->isSeekable()) {
$stream->seek(0);
}
return $stream;
} }
/** /**