From ae0c01c3beb64715fcc8182d544c3faa16f420e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=AE=89=E6=AD=A3=E8=B6=85?= Date: Thu, 10 Mar 2022 10:51:58 +0800 Subject: [PATCH] =?UTF-8?q?Bugfix:=20=E4=BF=AE=E5=A4=8D=20PSR-7=20Response?= =?UTF-8?q?=20=E7=94=A8=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `$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 相关讨论: - https://github.com/Nyholm/psr7/pull/176 --- src/think/route/Dispatch.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/think/route/Dispatch.php b/src/think/route/Dispatch.php index 0599dc1e3c..58666b50c9 100644 --- a/src/think/route/Dispatch.php +++ b/src/think/route/Dispatch.php @@ -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)]);