This commit is contained in:
as2252258@163.com
2021-07-26 12:48:31 +08:00
parent 60382f2b97
commit 95c9e878a5
2 changed files with 626 additions and 624 deletions
+8 -1
View File
@@ -525,7 +525,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)) {
$this->response->setFormat(Response::HTML); $this->response->setFormat(Response::HTML);
$this->response->send('<h1>404</h1>'); $this->response->send('<h1 style="text-align: center;">404</h1>');
} else { } else {
$this->response->send(($response = $node->dispatch()), 200); $this->response->send(($response = $node->dispatch()), 200);
if ($node->hasAfter()) { if ($node->hasAfter()) {
@@ -535,6 +535,13 @@ class Router extends HttpService implements RouterInterface
} }
public function status404()
{
$this->response->setFormat(Response::HTML);
$this->response->send('<h1 style="text-align: center;">404</h1>');
}
/** /**
* @param $exception * @param $exception
* @return mixed * @return mixed
+4 -9
View File
@@ -106,16 +106,11 @@ class HTTPServerListener extends Abstracts\Server
public function onRequest(Request $request, Response $response) public function onRequest(Request $request, Response $response)
{ {
try { try {
if (ApplicationStore::getStore()->getStatus() == 'exit') { if (HRequest::create($request, $response)->is('favicon.ico')) {
$response->status(401); $this->router->status404();
$response->end(); } else {
return;
}
$request = HRequest::create($request, $response);
if ($request->is('favicon.ico')) {
throw new Exception('Not found.', 404);
}
$this->router->dispatch(); $this->router->dispatch();
}
} catch (ExitException | Error | Throwable $exception) { } catch (ExitException | Error | Throwable $exception) {
$response->setHeader('Content-Type', 'text/html; charset=utf-8'); $response->setHeader('Content-Type', 'text/html; charset=utf-8');
$response->status($exception->getCode() == 0 ? 500 : $exception->getCode()); $response->status($exception->getCode() == 0 ? 500 : $exception->getCode());