diff --git a/http-helper/Route/Node.php b/http-helper/Route/Node.php
index eba17073..d83ce5b0 100644
--- a/http-helper/Route/Node.php
+++ b/http-helper/Route/Node.php
@@ -16,6 +16,7 @@ use Kiri\Exception\NotFindClassException;
use Kiri\IAspect;
use Kiri\Kiri;
use ReflectionException;
+use Server\Constant;
use Server\Events\OnAfterWorkerStart;
use Server\RequestInterface;
@@ -322,11 +323,11 @@ class Node
public function dispatch(RequestInterface $request): mixed
{
if (!in_array($request->getMethod(), $this->method)) {
- throw new RequestException('
HTTP 405 Method allow
Powered by Swoole', 405);
+ throw new RequestException(Constant::STATUS_405_MESSAGE, 405);
}
$handlerProviders = HandlerProviders::get($this->sourcePath, $request->getMethod());
if (empty($handlerProviders)) {
- throw new RequestException('HTTP 404 Not Found
Powered by Swoole', 404);
+ throw new RequestException(Constant::STATUS_404_MESSAGE, 404);
}
return $handlerProviders->interpreter($request);
}
diff --git a/http-server/Constant.php b/http-server/Constant.php
index a2a853c1..aa796163 100644
--- a/http-server/Constant.php
+++ b/http-server/Constant.php
@@ -11,36 +11,37 @@ namespace Server;
class Constant
{
- const START = 'Start';
- const SHUTDOWN = 'Shutdown';
- const WORKER_START = 'WorkerStart';
- const WORKER_STOP = 'WorkerStop';
- const WORKER_EXIT = 'WorkerExit';
- const CONNECT = 'Connect';
- const HANDSHAKE = 'handshake';
- const DISCONNECT = 'disconnect';
- const MESSAGE = 'message';
- const RECEIVE = 'Receive';
- const PACKET = 'Packet';
- const REQUEST = 'request';
- const CLOSE = 'Close';
- const TASK = 'Task';
- const FINISH = 'Finish';
- const PIPE_MESSAGE = 'PipeMessage';
- const WORKER_ERROR = 'WorkerError';
- const MANAGER_START = 'ManagerStart';
- const MANAGER_STOP = 'ManagerStop';
- const BEFORE_RELOAD = 'BeforeReload';
- const AFTER_RELOAD = 'AfterReload';
+ const START = 'Start';
+ const SHUTDOWN = 'Shutdown';
+ const WORKER_START = 'WorkerStart';
+ const WORKER_STOP = 'WorkerStop';
+ const WORKER_EXIT = 'WorkerExit';
+ const CONNECT = 'Connect';
+ const HANDSHAKE = 'handshake';
+ const DISCONNECT = 'disconnect';
+ const MESSAGE = 'message';
+ const RECEIVE = 'Receive';
+ const PACKET = 'Packet';
+ const REQUEST = 'request';
+ const CLOSE = 'Close';
+ const TASK = 'Task';
+ const FINISH = 'Finish';
+ const PIPE_MESSAGE = 'PipeMessage';
+ const WORKER_ERROR = 'WorkerError';
+ const MANAGER_START = 'ManagerStart';
+ const MANAGER_STOP = 'ManagerStop';
+ const BEFORE_RELOAD = 'BeforeReload';
+ const AFTER_RELOAD = 'AfterReload';
+ const SERVER_TYPE_HTTP = 'http';
+ const SERVER_TYPE_WEBSOCKET = 'ws';
+ const SERVER_TYPE_TCP = 'tcp';
+ const SERVER_TYPE_UDP = 'udp';
+ const SERVER_TYPE_BASE = 'base';
-
- const SERVER_TYPE_HTTP = 'http';
- const SERVER_TYPE_WEBSOCKET = 'ws';
- const SERVER_TYPE_TCP = 'tcp';
- const SERVER_TYPE_UDP = 'udp';
- const SERVER_TYPE_BASE = 'base';
+ const STATUS_404_MESSAGE = 'HTTP 404 Not Found
Powered by Swoole';
+ const STATUS_405_MESSAGE = 'HTTP 405 Method allow
Powered by Swoole';
}
diff --git a/http-server/Service/Http.php b/http-server/Service/Http.php
index 2fcd127b..542cc15e 100644
--- a/http-server/Service/Http.php
+++ b/http-server/Service/Http.php
@@ -7,6 +7,7 @@ use Exception;
use Http\Exception\RequestException;
use Http\Route\Node;
use Kiri\Core\Help;
+use Server\Constant;
use Server\Events\OnAfterRequest;
use Server\Message\Response as MsgResponse;
use Server\RequestInterface;
@@ -46,9 +47,10 @@ class Http extends \Server\Abstracts\Http implements OnClose, OnConnect
/** @var RequestInterface $request */
$node = $this->router->Branch_search($request);
if (!($node instanceof Node)) {
- throw new RequestException('HTTP 404 Not Found
Powered by Swoole', 404);
+ throw new RequestException(Constant::STATUS_404_MESSAGE, 404);
}
- if (!(($psr7Response = $node->dispatch($request)) instanceof ResponseInterface)) {
+ $psr7Response = $node->dispatch($request);
+ if (!($psr7Response instanceof ResponseInterface)) {
$psr7Response = $this->transferToResponse($psr7Response);
}
} catch (Error | \Throwable $exception) {