This commit is contained in:
2020-09-08 01:01:58 +08:00
parent d84ceaa353
commit 26d81cd8bc
2 changed files with 9 additions and 10 deletions
+6 -2
View File
@@ -115,11 +115,15 @@ class HttpHeaders
/** /**
* @param $name * @param $name
* @param null $default
* @return mixed|string|null * @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;
} }
+3 -8
View File
@@ -54,16 +54,14 @@ class Router extends Application implements RouterInterface
$paths = array_column($this->groupTacks, 'prefix'); $paths = array_column($this->groupTacks, 'prefix');
if (empty($paths)) { if (empty($paths)) {
$path = ltrim($path, '/'); $path = '/' . ltrim($path, '/');
} else { } else {
if ($path !== '/') { if ($path !== '/') {
$path = implode('/', $paths) . '/' . ltrim($path, '/'); $path = implode('/', $paths) . '/' . ltrim($path, '/');
} else { } else {
$path = implode('/', $paths); $path = implode('/', $paths);
} }
} $path = '/' . $path;
if (empty($path)) {
$path = '/';
} }
// $parent = $this->nodes[$method][$first] ?? null; // $parent = $this->nodes[$method][$first] ?? null;
@@ -438,10 +436,7 @@ class Router extends Application implements RouterInterface
return null; return null;
} }
$methods = $this->nodes[$method]; $methods = $this->nodes[$method];
$uri = ltrim($request->headers->getHeader('request_uri'), '/'); $uri = $request->headers->get('request_uri', '/');
if (empty($uri)) {
$uri = '/';
}
if (!isset($methods[$uri])) { if (!isset($methods[$uri])) {
if ($request->isOption) { if ($request->isOption) {
return $this->search_options($request); return $this->search_options($request);