guzzle-cache-middleware
guzzle-cache-middleware copied to clipboard
CacheEntry::__sleep mutates response body to PumpStream which is read once
Hello
CacheEntry::__sleep mutates response body to a PumpStream which is read once; if you try to re-read the response body you'll get an empty string.
I guess the current implementation assumes a CacheEntry is never used after being serialized, so PumpStreamd response is never exposed outside the middleware, but you can actually end-up with a mutated CacheEntry quite easily.
For instance, if you use a Symfony/cache PSR cache storage implementation with multiple serializing adapters :
On $this->cachePool->getItem($key); the ChainAdapter getting a hit on an outer adapter will save($item) on inner adapters, that will trigger __sleep, then return $item with the PumpStream implementation of bodies on request and response.