Skip to content

Commit

Permalink
Merge pull request #278 from saloonphp/fix/rewind-stream-before-acces…
Browse files Browse the repository at this point in the history
…sing

Fix | Rewind Stream Before Being Accessed
  • Loading branch information
Sammyjo20 committed Aug 27, 2023
2 parents 09fffb1 + 690df1d commit 53da4fb
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,7 @@ public function getPsrResponse(): ResponseInterface
*/
public function body(): string
{
$stream = $this->stream();
$body = $stream->getContents();

if ($stream->isSeekable()) {
$stream->rewind();
}

return $body;
return $this->stream()->getContents();
}

/**
Expand All @@ -122,7 +115,13 @@ public function body(): string
*/
public function stream(): StreamInterface
{
return $this->psrResponse->getBody();
$stream = $this->psrResponse->getBody();

if ($stream->isSeekable()) {
$stream->rewind();
}

return $stream;
}

/**
Expand Down

0 comments on commit 53da4fb

Please sign in to comment.