From 6897c11b0256d9f9dc8e636efc33a7da09599636 Mon Sep 17 00:00:00 2001 From: top_nuomi <1130395124@qq.com> Date: Sat, 31 Aug 2019 16:03:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84=E5=93=8D=E5=BA=94=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- framework/library/App.php | 6 ++++-- framework/library/http/Response.php | 26 +++++++++++++++++++------- framework/middleware/View.php | 4 +++- 3 files changed, 26 insertions(+), 10 deletions(-) diff --git a/framework/library/App.php b/framework/library/App.php index 32052be..a6e7d90 100644 --- a/framework/library/App.php +++ b/framework/library/App.php @@ -44,10 +44,12 @@ class App $response = Response::instance(); // 处理请求并得到数据 - $responseData = $response->dispatch($request->execute($type, $defaultModule)); + $responseData = $response->header([ + 'X-Powered-By: TOP-Framework' + ])->dispatch($request->execute($type, $defaultModule)); // 输出内容 - echo $responseData; + echo $responseData->content; } } diff --git a/framework/library/http/Response.php b/framework/library/http/Response.php index 9366890..ed34a6e 100644 --- a/framework/library/http/Response.php +++ b/framework/library/http/Response.php @@ -19,7 +19,7 @@ class Response * 响应内容 * @var null */ - private $content = null; + public $content = null; /** * 响应头 @@ -29,11 +29,19 @@ class Response /** * 设置Header - * @param array $header + * @param null $header * @return $this */ - public function header($header = []) + public function header($header = null) { + if (is_array($header)) { + $this->header = array_merge($this->header, $header); + } else { + $this->header[] = $header; + } + foreach ($this->header as $value) { + header($value); + } return $this; } @@ -44,11 +52,15 @@ class Response */ public function dispatch($data) { - // 处理响应数据,并返回 - $responseData = new ResponseData($data); - $this->content = $responseData->dispatch(); + if ($data instanceof Response) { + return $data; + } else { + // 处理响应数据,并返回 + $responseData = new ResponseData($data); + $this->content = $responseData->dispatch(); - return $this->content; + return $this; + } } } \ No newline at end of file diff --git a/framework/middleware/View.php b/framework/middleware/View.php index 5eda809..aabf713 100644 --- a/framework/middleware/View.php +++ b/framework/middleware/View.php @@ -19,7 +19,9 @@ class View implements MiddlewareIfs $cache = File::instance($config['cacheDir']); if ($cache->exists($ident)) { $content = $cache->get($ident); - return Response::instance()->dispatch($content); + return Response::instance()->header([ + 'HTTP/1.1 304 Not Modified' + ])->dispatch($content); } } return true;