Skip to content

Commit d11b71a

Browse files
overtrueliu21st
authored andcommitted
Bugfix: 修复 PSR-7 Response 用法
`$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
1 parent dcfa637 commit d11b71a

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/think/route/Dispatch.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ protected function autoResponse($data): Response
9696
if ($data instanceof Response) {
9797
$response = $data;
9898
} elseif ($data instanceof ResponseInterface) {
99-
$response = Response::create($data->getBody()->getContents(), 'html', $data->getStatusCode());
99+
$response = Response::create((string) $data->getBody(), 'html', $data->getStatusCode());
100100

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

0 commit comments

Comments
 (0)