改名
This commit is contained in:
@@ -470,17 +470,4 @@ class Request extends HttpService
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param string $key
|
|
||||||
* @param mixed|null $defaultValue
|
|
||||||
* @return mixed
|
|
||||||
*/
|
|
||||||
public function post(string $key, mixed $defaultValue = null): mixed
|
|
||||||
{
|
|
||||||
/** @var HttpParams $params */
|
|
||||||
$params = Context::getContext(HttpParams::class);
|
|
||||||
return $params->post($key, $defaultValue);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,8 +3,7 @@
|
|||||||
namespace Server;
|
namespace Server;
|
||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use HttpServer\Http\Request as HRequest;
|
use HttpServer\Route\Node;
|
||||||
use HttpServer\Http\Response as HResponse;
|
|
||||||
use HttpServer\Route\Router;
|
use HttpServer\Route\Router;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
use Snowflake\Event;
|
use Snowflake\Event;
|
||||||
@@ -101,24 +100,35 @@ class HTTPServerListener extends Abstracts\Server
|
|||||||
*/
|
*/
|
||||||
public function onRequest(Request $request, Response $response)
|
public function onRequest(Request $request, Response $response)
|
||||||
{
|
{
|
||||||
[$sRequest, $sResponse] = [HRequest::create($request), HResponse::create($response)];
|
|
||||||
try {
|
try {
|
||||||
|
defer(fn() => fire(Event::SYSTEM_RESOURCE_RELEASES));
|
||||||
|
[$sRequest, $sResponse] = $this->request($request, $response);
|
||||||
$node = $this->router->find_path($sRequest);
|
$node = $this->router->find_path($sRequest);
|
||||||
if (empty($node)) {
|
if ($node instanceof Node) {
|
||||||
|
$sResponse->send($node->dispatch());
|
||||||
|
} else {
|
||||||
$sResponse->send('404', 404);
|
$sResponse->send('404', 404);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
$sResponse->send($node->dispatch(), 200);
|
|
||||||
} catch (Error | Throwable $exception) {
|
} catch (Error | Throwable $exception) {
|
||||||
$sResponse->addHeader('Content-Type', 'text/html; charset=utf-8');
|
$response->setHeader('Content-Type', 'text/html; charset=utf-8');
|
||||||
$sResponse->send(jTraceEx($exception, null, true),
|
$response->setStatusCode(500);
|
||||||
$exception->getCode() == 0 ? 500 : $exception->getCode());
|
$response->end(jTraceEx($exception, null, true));
|
||||||
} finally {
|
|
||||||
$this->_event->dispatch(Event::SYSTEM_RESOURCE_RELEASES);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param Request $request
|
||||||
|
* @param Response $response
|
||||||
|
* @return array
|
||||||
|
* @throws Exception
|
||||||
|
*/
|
||||||
|
public function request(Request $request, Response $response): array
|
||||||
|
{
|
||||||
|
return [\HttpServer\Http\Request::create($request), \HttpServer\Http\Response::create($response)];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param Server $server
|
* @param Server $server
|
||||||
* @param int $fd
|
* @param int $fd
|
||||||
|
|||||||
Reference in New Issue
Block a user