This commit is contained in:
2021-09-06 18:54:14 +08:00
parent 74222ea346
commit 3e6d11f76f
2 changed files with 17 additions and 18 deletions
+2 -1
View File
@@ -418,6 +418,7 @@ class Router extends HttpService implements RouterInterface
public function split($path): ?array public function split($path): ?array
{ {
$path = $this->addPrefix() . '/' . ltrim($path, '/'); $path = $this->addPrefix() . '/' . ltrim($path, '/');
return [$path];
if ($path === '/') { if ($path === '/') {
return ['/']; return ['/'];
} }
@@ -505,7 +506,7 @@ class Router extends HttpService implements RouterInterface
// } // }
// } else { // } else {
// } // }
$node = $this->tree_search($uri->getExplode()); $node = $this->tree_search([$uri->getPath()]);
if (!($node instanceof Node)) { if (!($node instanceof Node)) {
return null; return null;
} }
+15 -17
View File
@@ -43,14 +43,13 @@ class Http extends \Server\Abstracts\Http implements OnClose, OnConnect
// TODO: Implement onRequest() method. // TODO: Implement onRequest() method.
try { try {
$request = \Server\Constrict\Request::create($request); $request = \Server\Constrict\Request::create($request);
// $node = $this->router->Branch_search($request); $node = $this->router->Branch_search($request);
// if (!($node instanceof Node)) { if (!($node instanceof Node)) {
// throw new RequestException('<h2>HTTP 404 Not Found</h2><hr><i>Powered by Swoole</i>', 404); throw new RequestException('<h2>HTTP 404 Not Found</h2><hr><i>Powered by Swoole</i>', 404);
// } }
// if (!(($responseData = $node->dispatch($request)) instanceof ResponseInterface)) { if (!(($responseData = $node->dispatch($request)) instanceof ResponseInterface)) {
// $responseData = $this->transferToResponse($responseData); $responseData = $this->transferToResponse($responseData);
// } }
$responseData = $this->transferToResponse('hello word.');
} catch (Error | \Throwable $exception) { } catch (Error | \Throwable $exception) {
$responseData = $this->exceptionHandler->emit($exception, $this->response); $responseData = $this->exceptionHandler->emit($exception, $this->response);
} finally { } finally {
@@ -71,15 +70,14 @@ class Http extends \Server\Abstracts\Http implements OnClose, OnConnect
if (!$interface->hasContentType()) { if (!$interface->hasContentType()) {
$interface->withContentType(MsgResponse::CONTENT_TYPE_JSON); $interface->withContentType(MsgResponse::CONTENT_TYPE_JSON);
} }
// $responseData = $interface->_toArray($responseData); $responseData = $interface->_toArray($responseData);
// if ($interface->getContentType() == MsgResponse::CONTENT_TYPE_XML) { if ($interface->getContentType() == MsgResponse::CONTENT_TYPE_XML) {
// $interface->stream->write(Help::toXml($responseData)); $interface->stream->write(Help::toXml($responseData));
// } else if (is_array($responseData)) { } else if (is_array($responseData)) {
// $interface->stream->write(json_encode($responseData)); $interface->stream->write(json_encode($responseData));
// } else { } else {
// $interface->stream->write((string)$responseData); $interface->stream->write((string)$responseData);
// } }
$interface->stream->write((string)$responseData);
return $interface; return $interface;
} }