Skip to content
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

Emit non seekable streams #2803

Merged
merged 3 commits into from Aug 15, 2019

Conversation

mapogolions
Copy link
Contributor

Every time when we emit any response we read all data from a stream twice.

There may be problems with slow streams or responses with too big body. In addition, with a such ResponseEmitter work, it is impossible to send a response with non seekable body.

@coveralls
Copy link

Coverage Status

Coverage remained the same at 100.0% when pulling a023af2 on mapogolions:fix/emit-non-seekable-stream into a1ca5e9 on slimphp:4.x.

if ($seekable) {
$stream->rewind();
}
return $seekable ? $stream->read(1) === '' : $stream->eof();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this be made easier with ... ?

return $stream->getSize() > 0;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your logic condition need to invert. return !$stream->getSize() > 0. Please, run unit tests with your code. You will see some errors (AppTest errors can be ignored). The most interesting is the error Slim\Tests\ResponseEmitterTest::testRespondIndeterminateLength. It shows that reading from a stream of at least one byte is the most reliable way. I myself don’t like such excessive complexity.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found yet another example. Resource $resource = popen('echo 12', 'r') will be defined as empty, but in reality has content.

@l0gicgate l0gicgate added this to the 4.2.0 milestone Aug 15, 2019
@l0gicgate l0gicgate merged commit 86a22f7 into slimphp:4.x Aug 15, 2019
@mapogolions mapogolions deleted the fix/emit-non-seekable-stream branch August 15, 2019 19:29
@l0gicgate l0gicgate mentioned this pull request Aug 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants