Skip to content

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

Merged
merged 2 commits into from
Feb 12, 2017
Merged

Do not rewind streams #72

merged 2 commits into from
Feb 12, 2017

Conversation

Nyholm
Copy link
Member

@Nyholm Nyholm commented Jan 16, 2017

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

@dbu
Copy link
Contributor

dbu commented Jan 16, 2017

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.

@Nyholm
Copy link
Member Author

Nyholm commented Jan 16, 2017

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?

@joelwurtz
Copy link
Member

joelwurtz commented Jan 16, 2017

Should we rewind streams and resources when they are passed in the factory?

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();
Copy link
Member Author

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.

@Nyholm
Copy link
Member Author

Nyholm commented Jan 27, 2017

Thank you for the feedback. Is this PR ready to be merged?
This PR is blocking: php-http/multipart-stream-builder#27

@sagikazarmark
Copy link
Member

sagikazarmark commented Jan 27, 2017

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.

@Nyholm
Copy link
Member Author

Nyholm commented Feb 9, 2017

How do http clients behave when they receive a request? Do they rewind the body?

php-http/curl-client: Does not rewind
php-http/socket-client: Does rewind
Guzzle: Uses __toString() which rewinds

What is our expectation (and current behaviour) in plugins (where we interact with streams the most apart from the client)?

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

@dbu
Copy link
Contributor

dbu commented Feb 9, 2017

now with your fix, curl-client does rewind as well

@Nyholm
Copy link
Member Author

Nyholm commented Feb 10, 2017

Yes, Correct. @sagikazarmark do you want to investigate some more before we merge? Do you think it is a good idea to merge?

@sagikazarmark
Copy link
Member

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?

@Nyholm
Copy link
Member Author

Nyholm commented Feb 11, 2017

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.

@sagikazarmark
Copy link
Member

Okay, so I am totally confused now I guess. 😄 Isn't this PR about REWINDING streams? Or about NOT REWINDING them?

@Nyholm Nyholm changed the title Test if we rewind existing stream/resource Do not rewind streams Feb 11, 2017
@Nyholm
Copy link
Member Author

Nyholm commented Feb 11, 2017

Sorry for the confusion. I updated the code after #72 (comment) but I did not update the title.

@sagikazarmark
Copy link
Member

Ah, okay. 😄 I was on the wrong path then for a long time ago.

@sagikazarmark
Copy link
Member

Good to go?

@Nyholm
Copy link
Member Author

Nyholm commented Feb 11, 2017

Yes!

@Nyholm Nyholm merged commit 6ffe75a into master Feb 12, 2017
@Nyholm Nyholm deleted the Nyholm-rewind branch February 12, 2017 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants