This commit is contained in:
2021-07-21 11:28:57 +08:00
parent 8f6079b040
commit 226094f844
2 changed files with 542 additions and 544 deletions
+1 -2
View File
@@ -7,7 +7,6 @@ use Closure;
use Exception; use Exception;
use HttpServer\Abstracts\HttpService; use HttpServer\Abstracts\HttpService;
use HttpServer\Controller; use HttpServer\Controller;
use HttpServer\Exception\RequestException;
use HttpServer\Http\Request; use HttpServer\Http\Request;
use HttpServer\IInterface\Middleware; use HttpServer\IInterface\Middleware;
use HttpServer\IInterface\RouterInterface; use HttpServer\IInterface\RouterInterface;
@@ -518,7 +517,7 @@ class Router extends HttpService implements RouterInterface
{ {
$node = $this->find_path(\request()); $node = $this->find_path(\request());
if (!($node instanceof Node)) { if (!($node instanceof Node)) {
throw new RequestException(\request()->getUri() . ' -> ' . self::NOT_FOUND, 404); return send(\request()->getUri() . ' -> ' . self::NOT_FOUND);
} }
send(($response = $node->dispatch()), 200); send(($response = $node->dispatch()), 200);
if (!$node->hasAfter()) { if (!$node->hasAfter()) {
+1 -2
View File
@@ -97,9 +97,8 @@ class HTTPServerListener extends Abstracts\Server
[$request, $response] = [HRequest::create($request), HResponse::create($response)]; [$request, $response] = [HRequest::create($request), HResponse::create($response)];
if ($request->is('favicon.ico')) { if ($request->is('favicon.ico')) {
throw new Exception('Not found.', 404); throw new Exception('Not found.', 404);
} else {
$this->router->dispatch();
} }
$this->router->dispatch();
} catch (ExitException | Error | Throwable $exception) { } catch (ExitException | Error | Throwable $exception) {
$response->status($exception->getCode() == 0 ? 500 : $exception->getCode()); $response->status($exception->getCode() == 0 ? 500 : $exception->getCode());
$response->end($exception->getMessage()); $response->end($exception->getMessage());