diff --git a/HttpServer/Http/HttpHeaders.php b/HttpServer/Http/HttpHeaders.php index edaa8d85..9146b5ec 100644 --- a/HttpServer/Http/HttpHeaders.php +++ b/HttpServer/Http/HttpHeaders.php @@ -59,7 +59,11 @@ class HttpHeaders */ public function getRequestUri(): ?string { - return $this->__handler__('request_uri'); + $uri = $this->__handler__('request_uri', '/'); + if (empty($uri)) { + return '/'; + } + return $uri; } diff --git a/HttpServer/Route/Router.php b/HttpServer/Route/Router.php index e99367d7..0cf762c4 100644 --- a/HttpServer/Route/Router.php +++ b/HttpServer/Route/Router.php @@ -3,7 +3,6 @@ declare(strict_types=1); namespace HttpServer\Route; -use Annotation\Route\Route; use Closure; use Exception; use HttpServer\Abstracts\HttpService; @@ -481,32 +480,6 @@ class Router extends HttpService implements RouterInterface } - /** - * @return mixed - * @throws - */ - public function dispatch(Request $request): void - { - $node = $this->find_path($request); - if (!($node instanceof Node)) { - $this->response->setFormat(Response::HTML); - $this->response->send('

HTTP 404 Not Found


Powered by Swoole'); - } else { - $this->response->send($node->dispatch(), 200); - } - } - - - /** - * @throws Exception - */ - public function pageNotFound() - { - $this->response->setFormat(Response::HTML); - $this->response->send('

HTTP 404 Not Found


Powered by Swoole'); - } - - /** * @param $exception * @return mixed @@ -522,13 +495,13 @@ class Router extends HttpService implements RouterInterface * @param Request $request * @return Node|null 树干搜索 * 树干搜索 + * @throws Exception */ public function find_path(Request $request): ?Node { $method = $request->getMethod(); - $uri = $request->headers->get('request_uri', '/'); - $methods = static::$nodes[$method][$uri] ?? null; + $methods = static::$nodes[$method][\request()->getUri()] ?? null; if (!is_null($methods)) { return $methods; }