Skip to content

Commit

Permalink
提前渲染模板,防止模板渲染时的错误无法显示
Browse files Browse the repository at this point in the history
  • Loading branch information
yunwuxin committed Oct 20, 2024
1 parent 9e77789 commit 6859577
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/concerns/InteractsWithHttp.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use think\helper\Arr;
use think\helper\Str;
use think\Http;
use think\response\View;
use think\swoole\App as SwooleApp;
use think\swoole\Http as SwooleHttp;
use think\swoole\response\File as FileResponse;
Expand Down Expand Up @@ -123,6 +124,7 @@ public function onRequest($req, $res)

try {
$response = $this->handleRequest($http, $request);
$this->prepareResponse($response);
} catch (Throwable $e) {
$handle = $this->app->make(Handle::class);
$handle->report($e);
Expand Down Expand Up @@ -182,6 +184,15 @@ protected function prepareRequest(Request $req)
->setPathinfo(ltrim($req->server['path_info'], '/'));
}

protected function prepareResponse(\think\Response $response)
{
switch (true) {
case $response instanceof View:
$response->getContent();
break;
}
}

protected function getFiles(Request $req)
{
if (empty($req->files)) {
Expand Down

2 comments on commit 6859577

@jialanmo
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yunwuxin 没有处理think\response\File,导致File的output()晚于setHeader(),header没有正确输出

@yunwuxin
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.