From 6b7e307948595550fa948378bd11467c0aaabf64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Wed, 4 Aug 2021 18:09:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HttpServer/Http/HttpHeaders.php | 6 +++++- HttpServer/Route/Router.php | 31 ++----------------------------- 2 files changed, 7 insertions(+), 30 deletions(-) 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; }