-
-
Notifications
You must be signed in to change notification settings - Fork 77
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
Body is always empty #135
Comments
For that last one, I would expect a fatal error (Object of class Nyholm\Psr7\Response could not be converted to string). Only Stream objects can be cast to a string. And when I use That one also describes one of our unit tests: testCanConstructWithBody. So I am not surprised that it works. Can you confirm that it works when you do not try to cast the entire Response object? The first one is … just not how For more reading, there is #99 which will also link you to my research about the problem on the PHP-FIG mailing list, as well as a link to a proposal for fixing it. |
Thanks for the response. I'll close as the other issue is already addressing my problem here. |
PHP FIG PSR-7 describes getContents as "Returns the *remaining* contents in a string", while the interface description mentions "[...] including serialization of the entire stream to a string.". For some implementations of PSR-7 the stream is not rewinded and thus getContents turns out to be an empty string in some cases. Also see https://github.com/php-fig/http-message/blob/efd67d1dc14a7ef4fc4e518e7dee91c271d524e4/src/StreamInterface.php#L136-L143 and Nyholm/psr7#135 (comment).
Version: 1.2.1
Steps to recreate:
$response = new \Nyholm\Psr7\Response(203, [], 'hello world'); var_dump($response->getBody()->getContents()); var_dump((string)$response);
Expectation:
Both
var_dump
calls dump "hello world"Actual result:
Both
var_dump
calls dump "" (an empty string)The text was updated successfully, but these errors were encountered: