Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/CachePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Http\Client\Common\Plugin;

use Http\Client\Common\Plugin;
use Http\Client\Common\Plugin\Exception\RewindStreamException;
use Http\Message\StreamFactory;
use Http\Promise\FulfilledPromise;
use Psr\Cache\CacheItemInterface;
Expand Down Expand Up @@ -379,7 +380,15 @@ private function createResponseFromCacheItem(CacheItemInterface $cacheItem)

/** @var ResponseInterface $response */
$response = $data['response'];
$response = $response->withBody($this->streamFactory->createStream($data['body']));
$stream = $this->streamFactory->createStream($data['body']);

try {
$stream->rewind();
} catch (\Exception $e) {
throw new RewindStreamException('Cannot rewind stream.', 0, $e);
}

$response = $response->withBody($stream);

return $response;
}
Expand Down
12 changes: 12 additions & 0 deletions src/Exception/RewindStreamException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Http\Client\Common\Plugin\Exception;

use Http\Client\Exception;

/**
* @author Théo FIDRY <[email protected]>
*/
class RewindStreamException extends \RuntimeException implements Exception
{
}