Skip to content

Commit

Permalink
Change how we fetch the initial contents to avoid having to rewind in…
Browse files Browse the repository at this point in the history
… getter (#11)
  • Loading branch information
tomb1n0 authored Sep 29, 2023
1 parent 2c39920 commit 5705431
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/Http/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,13 @@ public function __construct(
$this->response = $response;
$this->paginationHandler = $paginationHandler;

$this->contents = $this->response->getBody()->getContents();
$this->contents = (string) $this->response->getBody();

/**
* Now we've fetched the contents, rewind the stream to ensure anyone fetching the PSR-7 response
* can read the body correctly without having to rewind first.
*/
$this->response->getBody()->rewind();
}

public function toPsr7Request(): RequestInterface
Expand All @@ -73,9 +79,6 @@ public function toPsr7Request(): RequestInterface

public function toPsr7Response(): ResponseInterface
{
// Ensure the body is rewound so the consumer can read the contents of the body if they want to.
$this->response->getBody()->rewind();

return $this->response;
}

Expand Down

0 comments on commit 5705431

Please sign in to comment.