This commit is contained in:
2021-08-04 18:09:37 +08:00
parent d43bc87268
commit 6b7e307948
2 changed files with 7 additions and 30 deletions
+5 -1
View File
@@ -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;
}
+2 -29
View File
@@ -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('<h2>HTTP 404 Not Found</h2><hr><i>Powered by Swoole</i>');
} else {
$this->response->send($node->dispatch(), 200);
}
}
/**
* @throws Exception
*/
public function pageNotFound()
{
$this->response->setFormat(Response::HTML);
$this->response->send('<h2>HTTP 404 Not Found</h2><hr><i>Powered by Swoole</i>');
}
/**
* @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;
}