This commit is contained in:
2020-12-17 10:12:54 +08:00
parent f4893843cd
commit c85b5e003a
+18 -3
View File
@@ -12,10 +12,12 @@ use HttpServer\Http\Request as HRequest;
use HttpServer\Http\Response as HResponse;
use HttpServer\Route\Node;
use HttpServer\Service\Http;
use ReflectionException;
use Snowflake\Abstracts\Config;
use Snowflake\Core\JSON;
use Snowflake\Event;
use Snowflake\Exception\ComponentException;
use Snowflake\Exception\NotFindClassException;
use Snowflake\Snowflake;
use Swoole\Coroutine;
use Swoole\Error;
@@ -55,12 +57,12 @@ class OnRequest extends Callback
{
try {
/** @var HRequest $sRequest */
[$sRequest, $sResponse] = [HRequest::create($request), HResponse::create($response)];
[$sRequest, $sResponse] = $this->create($request, $response);
if ($sRequest->is('favicon.ico')) {
return $sResponse->send($sRequest->isNotFound(), 200);
} else {
return Snowflake::app()->getRouter()->dispatch();
}
return Snowflake::app()->getRouter()->dispatch();
} catch (ExitException $exception) {
return send($exception->getMessage(), $exception->getCode());
} catch (Error | \Throwable $exception) {
@@ -75,6 +77,19 @@ class OnRequest extends Callback
}
/**
* @param $request
* @param $response
* @return array
* @throws NotFindClassException
* @throws ReflectionException
*/
private function create($request, $response): array
{
return [HRequest::create($request), HResponse::create($response)];
}
/**
* @param $response
* @throws Exception