From f87c437d60b1bff95349cdfb63bfcfc10e066588 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 20 Jul 2021 11:48:41 +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 --- Server/HTTPServerListener.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/Server/HTTPServerListener.php b/Server/HTTPServerListener.php index 2c261900..a1dc9f8f 100644 --- a/Server/HTTPServerListener.php +++ b/Server/HTTPServerListener.php @@ -3,13 +3,19 @@ namespace Server; use Exception; +use HttpServer\Exception\ExitException; +use HttpServer\Http\Request as HRequest; +use HttpServer\Http\Response as HResponse; use HttpServer\Route\Router; use ReflectionException; +use Snowflake\Event; use Snowflake\Exception\NotFindClassException; use Snowflake\Snowflake; +use Swoole\Error; use Swoole\Http\Request; use Swoole\Http\Response; use Swoole\Server; +use Throwable; /** @@ -84,13 +90,20 @@ class HTTPServerListener extends Abstracts\Server */ public function onRequest(Request $request, Response $response) { - $this->router->find_path(new \HttpServer\Http\Request()); + try { + defer(fn() => fire(Event::SYSTEM_RESOURCE_RELEASES)); - if (!$response->isWritable()) { - return; + /** @var HResponse $response */ + [$request, $response] = [HRequest::create($request), HResponse::create($response)]; + if ($request->is('favicon.ico')) { + $response->close(404); + } else { + $this->router->dispatch(); + } + } catch (ExitException | Error | Throwable $exception) { + $response->status($exception->getCode() == 0 ? 500 : $exception->getCode()); + $response->end($exception->getMessage()); } - $response->status(200); - $response->end(''); }