Skip to content

Fix Stream::read($length) implementation #14

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 1 commit into from
Feb 19, 2016

Conversation

ajgarlag
Copy link
Contributor

When $length value exceeds the stream eof, the remaining stream content
must be returned.

See #13

@sagikazarmark
Copy link
Member

@ajgarlag thanks for the PR.

The tests are failing because of a dependency issue. I fixed it, also updated a few other dependencies in #15. Once @joelwurtz checks/merges it, you should rebase your branch. Checks should pass afterwards.

@@ -164,7 +164,7 @@ public function read($length)
}

if ($this->getSize() < ($this->readed + $length)) {
throw new StreamException('Cannot read more than %s', $this->getSize() - $this->readed);
return fread($this->socket, $this->getSize() - $this->readed);
}
Copy link
Member

Choose a reason for hiding this comment

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

Is this now needed at all? The fread() call below is able to handle this too, isn't it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are right!

@ajgarlag
Copy link
Contributor Author

@sagikazarmark I've rebased your branch, but the build still fails with PHP5.6 and PHP7.

Once #15 is fixed and merged, I will rebase master to finish the PR.

@sagikazarmark
Copy link
Member

Ok. It seems that the current failure is not related to dependency issues.

@joelwurtz
Copy link
Member

I'm not so sure about this change, IMO i prefer to have an exception when the user doesn't handle well the size of the stream.

For me this change should be in the documentation, where we should tell the user to check the size of stream before reading.

The PSR7 line is only a recommendation and is related to the fread implementation in PHP which can sometimes return less bytes than asked.

@ajgarlag
Copy link
Contributor Author

In my code, I was using Http\Message\Encoding\FilteredStream to read a gzipped Http\Client\Socket\Stream

To fill the FilteredStream buffer, the inner stream is read in chunks of 8192 bytes, which is defined by a constant, so I have no control of the stream size.

@joelwurtz
Copy link
Member

I see, you make me doubting, should the filtered stream be updated or this one ?

Just mad a test on fread, and it's silent when reading more data than asked, so we should keep the same behavior, like you propose.

@joelwurtz
Copy link
Member

Can you rebase on master ?

Will certainly throw a new version once this has been merged.

When `$length` value exceeds the stream eof, the remaining stream content
must be returned.
@ajgarlag
Copy link
Contributor Author

@joelwurtz Rebased and squashed.

The travis-ci build was successful before squashing, but failed after it.

Reviewing the test failure, I think it was a transient error, so this could be merged.

@joelwurtz
Copy link
Member

Yeah no big deal, thanks !

joelwurtz added a commit that referenced this pull request Feb 19, 2016
Fix `Stream::read($length)` implementation
@joelwurtz joelwurtz merged commit aca53b9 into php-http:master Feb 19, 2016
@ajgarlag
Copy link
Contributor Author

@joelwurtz Can you tag a new version with this fix?

@joelwurtz
Copy link
Member

Tagged in 1.1.0

@ajgarlag ajgarlag deleted the patch-1 branch February 25, 2016 10:45
@ajgarlag
Copy link
Contributor Author

Thanks!

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