bug #32691 [HttpClient] rewind streams created from strings (nicolas-grekas)

This PR was merged into the 4.4 branch.

Discussion
----------

[HttpClient] rewind streams created from strings

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

Follow up of #32689 for 4.4

Commits
-------

33ed4e43c4 [HttpClient] rewind streams created from strings
This commit is contained in:
Fabien Potencier 2019-07-24 12:20:39 +02:00
commit fad4104cf3
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 ?? '')) {
return $this->client->createStream($body ?? '');
$body = $this->client->createStream($body ?? '');
if ($body->isSeekable()) {
$body->seek(0);
}
return $body;
}
if (\is_resource($body)) {

View File

@ -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;
}
/**