From c85b5e003ae330853ae4530db71f454d1c7b8318 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Thu, 17 Dec 2020 10:12:54 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HttpServer/Events/OnRequest.php | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/HttpServer/Events/OnRequest.php b/HttpServer/Events/OnRequest.php index 200034ab..6233388d 100644 --- a/HttpServer/Events/OnRequest.php +++ b/HttpServer/Events/OnRequest.php @@ -12,10 +12,12 @@ use HttpServer\Http\Request as HRequest; use HttpServer\Http\Response as HResponse; use HttpServer\Route\Node; use HttpServer\Service\Http; +use ReflectionException; use Snowflake\Abstracts\Config; use Snowflake\Core\JSON; use Snowflake\Event; use Snowflake\Exception\ComponentException; +use Snowflake\Exception\NotFindClassException; use Snowflake\Snowflake; use Swoole\Coroutine; use Swoole\Error; @@ -55,12 +57,12 @@ class OnRequest extends Callback { try { /** @var HRequest $sRequest */ - [$sRequest, $sResponse] = [HRequest::create($request), HResponse::create($response)]; - + [$sRequest, $sResponse] = $this->create($request, $response); if ($sRequest->is('favicon.ico')) { return $sResponse->send($sRequest->isNotFound(), 200); + } else { + return Snowflake::app()->getRouter()->dispatch(); } - return Snowflake::app()->getRouter()->dispatch(); } catch (ExitException $exception) { return send($exception->getMessage(), $exception->getCode()); } catch (Error | \Throwable $exception) { @@ -75,6 +77,19 @@ class OnRequest extends Callback } + /** + * @param $request + * @param $response + * @return array + * @throws NotFindClassException + * @throws ReflectionException + */ + private function create($request, $response): array + { + return [HRequest::create($request), HResponse::create($response)]; + } + + /** * @param $response * @throws Exception