-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reading GzipDecodeStream causes Uncaught RuntimeException: Unable to perform operation on closed stream #90
Comments
A gzip stream should not be seekable / rewindable, so i suspect it miss an exception here. You can use a buffered stream to do that : $gzipStream = new \Http\Message\Stream\BufferedStream(new \Http\Message\Encoding\GzipDecodeStream($stream)); |
Thanks for the quick reply. That indeed does resolve this behaviour. |
No it should not, as buffering the stream is not so useful (only when you need to read multiple times the body) and consume memory / io and will slow down applications when dealing with big body. |
Thanks, I think that makes sense. If you build a client like this... return new PluginClient(
$httpClient,
[
CachePlugin::clientCache($cache, $streamFactory),
new DecoderPlugin([])
]
) ... which I think is reasonable, because you want your cache to be as efficient as possible, so putting it at the top of the chain makes it so it has the opportunity to satisfy the request from cache before doing unnecessary operations, then you'll run into this crash because CachePlugin will do... $bodyStream = $response->getBody();
$body = $bodyStream->__toString();
if ($bodyStream->isSeekable()) {
$bodyStream->rewind();
} else {
$response = $response->withBody($this->streamFactory->createStream($body));
} ... and then, at some point, your application code will probably do a second Would the recommended behaviour be |
Filtered stream should return false in fact, fixed in #100 |
Actual Behavior
What is the actual behavior?
PHP Fatal error: Uncaught RuntimeException: Unable to perform operation on closed stream in /Users/iconnor/Documents/PHP/php-http-message-bug/vendor/clue/stream-filter/src/functions.php:98
Expected Behavior
What is the behavior you expect?
The stream is rewindable. I should be able to read its contents, rewind it, and then read its contents again.
Steps to Reproduce
Checkout this repository https://github.com/iainconnor/php-http-message-bug/blob/master/demo.php run demo.php.
Or,
Possible Solutions
If you have already ideas how to solve the issue, add them here.
(remove this section if not needed)
These lines -- https://github.com/php-http/message/blob/master/src/Encoding/FilteredStream.php#L116-L118 -- look to be the cause, though I'm not sure on the solution.
The text was updated successfully, but these errors were encountered: