Closed Nyholm closed 8 years ago
Rewinding the stream is not hard, IF the stream is rewindable :)
If not the current design is broken as we have to replace the stream in the request passed to the formatter but since the request is immutable we cannot update the stream easily.
Then there is some work to do in the plugin calling the formatter which holds the responsability of rewinding / replacing the stream.
Also cloning / rewinding the stream is something that it's used in the cache plugin, maybe we can refactor this part to have an helper stream / class doing this ?
👍 For a helper class doing this. I did the same hack in an other PR: https://github.com/KnpLabs/php-github-api/pull/389/files#diff-192f7f95a475a8e6e67b97d1c5125367R22
Not too sure how to solve the broken design though... Maybe do not read the stream if it not is rewindable/seekable?
Or copy the stream.
Or copy the stream.
we should try to avoid that. the memory impact can be massive. i think we should by default leave the body alone, especially if its not rewindable, and probably have 3 options: don't show body, show body if stream can rewind, always show body (and copy streams if needed)
We cant copy the string because the Request is immutable.
I've created a PR.
Actual Behavior
From: https://github.com/php-http/HttplugBundle/pull/84#issuecomment-232911288
Streams should be rewinded after they are read.