-
Notifications
You must be signed in to change notification settings - Fork 39
Do not rewind streams #72
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
Conversation
if we don't read from the stream, we also should not rewind it. i am a bit afraid about the side effect if we change behaviour within a minor version. we should probably only do that for version 2 and add notes to the corresponding changelogs. |
I think we can update this behavior in a patch release. The factories are not interchangeable, which is a bug. What I want to know is: What is our intent? I agree that we should not touch an existing StreamInterface. Why do we like to rewind it? What benefits does it give? |
IMO no We should only rewind when we read something and we know that another piece of code will certainly need to read it to. |
} | ||
|
||
if ($body->isSeekable()) { | ||
$body->rewind(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we do not have to rewind the stream I could reduce the complexity and increase readability of the factories.
Thank you for the feedback. Is this PR ready to be merged? |
How do http clients behave when they receive a request? Do they rewind the body? What is our expectation (and current behaviour) in plugins (where we interact with streams the most apart from the client)? I guess these need to be taken into account as well. Maybe we could test this branch in our integration test suite with different clients. |
php-http/curl-client: Does not rewind
Plugins that handles responses do always rewind the stream. The end user should not get different responses depending on if a plugin (say LogPlugin) is used or not. I believe it is the client's responsibility to rewind the stream. Why would you ever want to create a stream, seek to 50% and then just send the second half as a HTTP request? I will send a PR to php-http/curl-client |
now with your fix, curl-client does rewind as well |
Yes, Correct. @sagikazarmark do you want to investigate some more before we merge? Do you think it is a good idea to merge? |
No, if the consensous is that clients mostly rewind, I am fine with that, users probably expect that behaviour anyway. Also, stream factories will probably never produce a non-seekable stream. There is one risk though: one might pass in a stream which is read only, non-seekable. How do we handle that case? |
We do not touch streams at all. We just return them. Same with resources. We do not read form them at all, just wrap them in a stream. |
Okay, so I am totally confused now I guess. 😄 Isn't this PR about REWINDING streams? Or about NOT REWINDING them? |
Sorry for the confusion. I updated the code after #72 (comment) but I did not update the title. |
Ah, okay. 😄 I was on the wrong path then for a long time ago. |
Good to go? |
Yes! |
Should we rewind streams and resources when they are passed in the factory?
Guzzle does not rewind at all.
Slim rewinds resources but not streams.
Zend rewinds everything.
This is related to #71