modify
This commit is contained in:
@@ -6,6 +6,7 @@ use Annotation\Inject;
|
||||
use Exception;
|
||||
use HttpServer\Http\Context;
|
||||
use HttpServer\Http\Request as HSRequest;
|
||||
use HttpServer\Route\Node;
|
||||
use HttpServer\Route\Router;
|
||||
use Server\Events\OnAfterRequest;
|
||||
use Snowflake\Event;
|
||||
@@ -39,6 +40,7 @@ class HTTPServerListener extends Abstracts\Server
|
||||
public \HttpServer\Http\Response $response;
|
||||
|
||||
|
||||
|
||||
/** @var EventDispatch */
|
||||
#[Inject(EventDispatch::class)]
|
||||
public EventDispatch $eventDispatch;
|
||||
@@ -90,15 +92,20 @@ class HTTPServerListener extends Abstracts\Server
|
||||
public function onRequest(Request $request, Response $response)
|
||||
{
|
||||
try {
|
||||
Context::setContext(Response::class, $response);
|
||||
|
||||
HSRequest::create($request);
|
||||
// $this->router->dispatch(HSRequest::create($request));
|
||||
} catch (Error | Throwable $exception) {
|
||||
// $this->response->send(jTraceEx($exception), 500);
|
||||
$node = $this->router->find_path(HSRequest::create($request));
|
||||
if (!($node instanceof Node)) {
|
||||
$this->response->setFormat(\HttpServer\Http\Response::HTML);
|
||||
$data = '<h2>HTTP 404 Not Found</h2><hr><i>Powered by Swoole</i>';
|
||||
} else {
|
||||
$data= $node->dispatch();
|
||||
}
|
||||
} catch (Error | Throwable $exception) {
|
||||
$data = jTraceEx($exception);
|
||||
} finally {
|
||||
$response->status(200);
|
||||
$response->end('ok');
|
||||
if (Context::hasContext(Response::class)) {
|
||||
return;
|
||||
}
|
||||
Context::getContext(Response::class)->send($data,200, $response);
|
||||
$this->eventDispatch->dispatch(new OnAfterRequest());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user