From 5eece32104f0a51331c2b9458fd3c0221331b4b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Mon, 7 Sep 2020 11:16:41 +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/Route/Router.php | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/HttpServer/Route/Router.php b/HttpServer/Route/Router.php index bc3e4b6e..666f2987 100644 --- a/HttpServer/Route/Router.php +++ b/HttpServer/Route/Router.php @@ -440,6 +440,9 @@ class Router extends Application implements RouterInterface $methods = $this->nodes[$method]; $uri = ltrim($request->headers->getHeader('request_uri'), '/'); if (!isset($methods[$uri])) { + if ($request->isOption) { + return $this->search_options($request); + } return null; } return $this->nodes[$method][$uri]; @@ -447,6 +450,28 @@ class Router extends Application implements RouterInterface } + /** + * @param $request + * @return Node|null + */ + private function search_options($request) + { + $method = $request->getMethod(); + if (!isset($this->nodes[$method])) { + return null; + } + if (!isset($this->nodes[$method]['*'])) { + return null; + } + return $this->nodes[$method]['*']; + $node = $this->tree_search(['*'], $request->getMethod()); + if (!($node instanceof Node)) { + return null; + } + return $node; + } + + /** * @param $request * @return Node|null