diff --git a/HttpServer/Http/HttpHeaders.php b/HttpServer/Http/HttpHeaders.php index 597b583e..4675aefe 100644 --- a/HttpServer/Http/HttpHeaders.php +++ b/HttpServer/Http/HttpHeaders.php @@ -115,11 +115,15 @@ class HttpHeaders /** * @param $name + * @param null $default * @return mixed|string|null */ - public function get($name) + public function get($name, $default = null) { - return $this->getHeader($name); + if (empty($value = $this->getHeader($name))) { + return $default; + } + return $value; } diff --git a/HttpServer/Route/Router.php b/HttpServer/Route/Router.php index 9d08d0ae..345fec6d 100644 --- a/HttpServer/Route/Router.php +++ b/HttpServer/Route/Router.php @@ -54,16 +54,14 @@ class Router extends Application implements RouterInterface $paths = array_column($this->groupTacks, 'prefix'); if (empty($paths)) { - $path = ltrim($path, '/'); + $path = '/' . ltrim($path, '/'); } else { if ($path !== '/') { $path = implode('/', $paths) . '/' . ltrim($path, '/'); } else { $path = implode('/', $paths); } - } - if (empty($path)) { - $path = '/'; + $path = '/' . $path; } // $parent = $this->nodes[$method][$first] ?? null; @@ -438,10 +436,7 @@ class Router extends Application implements RouterInterface return null; } $methods = $this->nodes[$method]; - $uri = ltrim($request->headers->getHeader('request_uri'), '/'); - if (empty($uri)) { - $uri = '/'; - } + $uri = $request->headers->get('request_uri', '/'); if (!isset($methods[$uri])) { if ($request->isOption) { return $this->search_options($request);