改名
This commit is contained in:
@@ -495,60 +495,4 @@ class Request extends HttpService
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $fd
|
||||
* @param $data
|
||||
* @param int $reID
|
||||
* @return mixed|null
|
||||
* @throws ConfigException
|
||||
* @throws Exception
|
||||
*/
|
||||
public static function rpcRequest($fd, $data, int $reID = 0): Request|null
|
||||
{
|
||||
$sRequest = new Request();
|
||||
|
||||
$sRequest->fd = is_array($fd) ? 0 : $fd;
|
||||
$sRequest->clientInfo = self::getClientInfo($fd, $reID);
|
||||
$sRequest->startTime = microtime(true);
|
||||
$sRequest->headers = new HttpHeaders([]);
|
||||
$sRequest->params = new HttpParams($data, [], []);
|
||||
|
||||
$port = $sRequest->clientInfo['server_port'];
|
||||
if (($rpc = Config::get('rpc.port', 0)) !== $port) {
|
||||
return null;
|
||||
}
|
||||
|
||||
[$cmd, $repeat, $body] = explode("\n", $sRequest->params->getBody());
|
||||
if (is_null($body) || is_null($cmd) || !empty($repeat)) {
|
||||
throw new Exception('Protocol format error.');
|
||||
}
|
||||
|
||||
if (is_string($body) && is_null($data = Json::decode($body))) {
|
||||
throw new Exception('Protocol format error.');
|
||||
}
|
||||
|
||||
$sRequest->params->setPosts($data);
|
||||
$sRequest->headers->setRequestUri('rpc/p' . $rpc . '/' . ltrim($cmd, '/'));
|
||||
$sRequest->headers->setRequestMethod(Request::HTTP_CMD);
|
||||
|
||||
return Context::setContext('request', $sRequest);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $fd
|
||||
* @param int $re
|
||||
* @return mixed
|
||||
* @throws Exception
|
||||
*/
|
||||
private static function getClientInfo($fd, int $re = 0): mixed
|
||||
{
|
||||
$server = Snowflake::app()->getSwoole();
|
||||
if (!is_array($fd)) {
|
||||
return $server->getClientInfo($fd, $re);
|
||||
}
|
||||
return $fd;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user