Skip to content

Commit

Permalink
Bugfix: 修复 PSR-7 Response 用法
Browse files Browse the repository at this point in the history
`$response->getBody()->getContents()` 并不能保证拿到完整内容,PSR-7 里的原话:

> Each stream instance will have various capabilities: it can be read-only, write-only, or read-write. It can also allow arbitrary random access (seeking forwards or backwards to any location), or only sequential access (for example in the case of a socket, pipe, or callback-based stream).
>
> Finally, StreamInterface defines a __toString() method to simplify retrieving or emitting the entire body contents at once.
> -- https://www.php-fig.org/psr/psr-7/#13-streams

相关讨论:
- Nyholm/psr7#176
  • Loading branch information
overtrue authored and liu21st committed Mar 10, 2022
1 parent dcfa637 commit d11b71a
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/think/route/Dispatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ protected function autoResponse($data): Response
if ($data instanceof Response) {
$response = $data;
} elseif ($data instanceof ResponseInterface) {
$response = Response::create($data->getBody()->getContents(), 'html', $data->getStatusCode());
$response = Response::create((string) $data->getBody(), 'html', $data->getStatusCode());

foreach ($data->getHeaders() as $header => $values) {
$response->header([$header => implode(", ", $values)]);
Expand Down

0 comments on commit d11b71a

Please sign in to comment.