Skip to content

Commit 5705431

Browse files
authored
Change how we fetch the initial contents to avoid having to rewind in getter (#11)
1 parent 2c39920 commit 5705431

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/Http/Response.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,13 @@ public function __construct(
6363
$this->response = $response;
6464
$this->paginationHandler = $paginationHandler;
6565

66-
$this->contents = $this->response->getBody()->getContents();
66+
$this->contents = (string) $this->response->getBody();
67+
68+
/**
69+
* Now we've fetched the contents, rewind the stream to ensure anyone fetching the PSR-7 response
70+
* can read the body correctly without having to rewind first.
71+
*/
72+
$this->response->getBody()->rewind();
6773
}
6874

6975
public function toPsr7Request(): RequestInterface
@@ -73,9 +79,6 @@ public function toPsr7Request(): RequestInterface
7379

7480
public function toPsr7Response(): ResponseInterface
7581
{
76-
// Ensure the body is rewound so the consumer can read the contents of the body if they want to.
77-
$this->response->getBody()->rewind();
78-
7982
return $this->response;
8083
}
8184

0 commit comments

Comments
 (0)