File tree 2 files changed +22
-1
lines changed
2 files changed +22
-1
lines changed Original file line number Diff line number Diff line change 3
3
namespace Http \Client \Common \Plugin ;
4
4
5
5
use Http \Client \Common \Plugin ;
6
+ use Http \Client \Common \Plugin \Exception \RewindStreamException ;
6
7
use Http \Message \StreamFactory ;
7
8
use Http \Promise \FulfilledPromise ;
8
9
use Psr \Cache \CacheItemInterface ;
@@ -379,7 +380,15 @@ private function createResponseFromCacheItem(CacheItemInterface $cacheItem)
379
380
380
381
/** @var ResponseInterface $response */
381
382
$ response = $ data ['response ' ];
382
- $ response = $ response ->withBody ($ this ->streamFactory ->createStream ($ data ['body ' ]));
383
+ $ stream = $ this ->streamFactory ->createStream ($ data ['body ' ]);
384
+
385
+ try {
386
+ $ stream ->rewind ();
387
+ } catch (\Exception $ e ) {
388
+ throw new RewindStreamException ('Cannot rewind stream. ' , 0 , $ e );
389
+ }
390
+
391
+ $ response = $ response ->withBody ($ stream );
383
392
384
393
return $ response ;
385
394
}
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Http \Client \Common \Plugin \Exception ;
4
+
5
+ use Http \Client \Exception ;
6
+
7
+ /**
8
+ * @author Théo FIDRY <theo.fidry@gmail.com>
9
+ */
10
+ class RewindStreamException extends \RuntimeException implements Exception
11
+ {
12
+ }
You can’t perform that action at this time.
0 commit comments