This commit is contained in:
2021-07-21 17:55:34 +08:00
parent 503a188dd7
commit ad43351306
3 changed files with 95 additions and 104 deletions
+5 -9
View File
@@ -545,21 +545,17 @@ class Router extends HttpService implements RouterInterface
*/
public function find_path(Request $request): ?Node
{
// return $this->Branch_search($request);
$method = $request->getMethod();
$uri = $request->headers->get('request_uri', '/');
if (!isset(static::$nodes[$method])) {
return null;
}
$methods = static::$nodes[$method];
if (isset($methods[$uri])) {
$methods = static::$nodes[$method][$uri] ?? null;
if (!is_null($methods[$uri])) {
return $methods[$uri];
}
if (!$request->isOption || !isset($methods['/'])) {
return null;
if ($request->isOption) {
return static::$nodes[$method]['*'] ?? null;
}
return $methods['/'];
return null;
}
+8 -5
View File
@@ -92,11 +92,14 @@ class Server extends HttpService
*/
private function rpcListener($rpcService)
{
$rpcService['events'][Constant::CONNECT] = [Service::class, 'onConnect'];
$rpcService['events'][Constant::DISCONNECT] = [Service::class, 'onClose'];
$rpcService['events'][Constant::CLOSE] = [Service::class, 'onClose'];
$rpcService['events'][Constant::RECEIVE] = [Service::class, 'onReceive'];
$rpcService['events'][Constant::PACKET] = [Service::class, 'onPacket'];
if (in_array($rpcService['mode'], [SWOOLE_SOCK_UDP, SWOOLE_UDP, SWOOLE_UDP6, SWOOLE_SOCK_UDP6])) {
$rpcService['events'][Constant::PACKET] = [Service::class, 'onPacket'];
} else {
$rpcService['events'][Constant::RECEIVE] = [Service::class, 'onReceive'];
$rpcService['events'][Constant::CONNECT] = [Service::class, 'onConnect'];
$rpcService['events'][Constant::DISCONNECT] = [Service::class, 'onDisconnect'];
$rpcService['events'][Constant::CLOSE] = [Service::class, 'onClose'];
}
$this->manager->addListener($rpcService['type'], $rpcService['host'], $rpcService['port'], $rpcService['mode'], $rpcService);
}