diff --git a/HttpServer/Events/OnRequest.php b/HttpServer/Events/OnRequest.php index 628b811d..1479486a 100644 --- a/HttpServer/Events/OnRequest.php +++ b/HttpServer/Events/OnRequest.php @@ -37,24 +37,21 @@ class OnRequest extends Callback public function onHandler(Request $request, Response $response) { try { + Coroutine::defer(function () { + fire(Event::EVENT_AFTER_REQUEST, [$sRequest ?? null]); + }); if (Config::get('debug.enable', false, false)) { function_exists('trackerHookMalloc') && trackerHookMalloc(); } /** @var HRequest $sRequest */ [$sRequest, $sResponse] = [HRequest::create($request), HResponse::create($response)]; if ($sRequest->is('favicon.ico')) { - return $params = $sResponse->send($sRequest->isNotFound(), 200); + $sResponse->send($sRequest->isNotFound(), 200); + } else { + Snowflake::app()->getRouter()->dispatch(); } - return $params = Snowflake::app()->getRouter()->dispatch(); } catch (Error | \Throwable $exception) { - $params = $this->sendErrorMessage($sResponse ?? null, $exception, $response); - } finally { - $events = Snowflake::app()->getEvent(); - if (!$events->exists(Event::EVENT_AFTER_REQUEST)) { - return; - } - $sRequest = $sRequest ?? null; - $events->trigger(Event::EVENT_AFTER_REQUEST, [$sRequest, $params ?? null]); + $this->sendErrorMessage($sResponse ?? null, $exception, $response); } } diff --git a/function.php b/function.php index 57f87716..a303a5b2 100644 --- a/function.php +++ b/function.php @@ -192,6 +192,22 @@ if (!function_exists('write')) { } } +if (!function_exists('fire')) { + + + /** + * @param string $event + * @param array $params + * @throws ComponentException + * @throws Exception + */ + function fire(string $event,array $params = []) + { + $logger = Snowflake::app()->getEvent(); + $logger->trigger($event, $params); + } +} + if (!function_exists('instance_load')) {