Skip to content

Commit

Permalink
Rewind to previous position after logging request & response body (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
siraic authored and Florian Preusner committed Sep 30, 2016
1 parent c0b7404 commit eb8746b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions Log/LogRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,15 @@ protected function save(RequestInterface $request) {
$this->setHeaders($request->getHeaders());
$this->setProtocolVersion($request->getProtocolVersion());
$this->setMethod($request->getMethod());

if($request->getBody()->isSeekable()) {
$readPosition = $request->getBody()->tell();
}
$this->setBody($request->getBody() ? $request->getBody()->__toString() : null);
if($request->getBody()->isSeekable()) {
$request->getBody()->seek($readPosition);
}

} // end: save()

/**
Expand Down
8 changes: 8 additions & 0 deletions Log/LogResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,15 @@ public function save(ResponseInterface $response) {

$this->setStatusCode($response->getStatusCode());
$this->setStatusPhrase($response->getReasonPhrase());

if($response->getBody()->isSeekable()) {
$readPosition = $response->getBody()->tell();
}
$this->setBody($response->getBody()->__toString());
if($response->getBody()->isSeekable()) {
$response->getBody()->seek($readPosition);
}

$this->setHeaders($response->getHeaders());
$this->setProtocolVersion($response->getProtocolVersion());
} // end: save()
Expand Down

0 comments on commit eb8746b

Please sign in to comment.