Skip to content

Commit

Permalink
Fix $response->getBody()->getContents() returns always empty content #48
Browse files Browse the repository at this point in the history
 (#80)
  • Loading branch information
Florian Preusner authored Dec 12, 2016
1 parent 2b6eb8a commit 88e1ed0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 11 deletions.
14 changes: 4 additions & 10 deletions Log/LogResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,17 +60,11 @@ public function save(ResponseInterface $response)
{
$this->setStatusCode($response->getStatusCode());
$this->setStatusPhrase($response->getReasonPhrase());
$this->setBody($response->getBody()->getContents());

// rewind to previous position after response body
$readPosition = null;
if($response->getBody()->isSeekable()) {
$readPosition = $response->getBody()->tell();
}

$this->setBody($response->getBody()->__toString());

if($readPosition) {
$response->getBody()->seek($readPosition);
// rewind to previous position after reading response body
if ($response->getBody()->isSeekable()) {
$response->getBody()->rewind();
}

$this->setHeaders($response->getHeaders());
Expand Down
2 changes: 1 addition & 1 deletion Tests/Log/LogResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function setUp()
->disableOriginalConstructor()
->getMock();

$bodyMock->method('__toString')->willReturn('test body');
$bodyMock->method('getContents')->willReturn('test body');

$this->response->method('getStatusCode')->willReturn(200);
$this->response->method('getHeaders')->willReturn($this->headers);
Expand Down

0 comments on commit 88e1ed0

Please sign in to comment.