改名
This commit is contained in:
+21
-14
@@ -113,8 +113,15 @@ class Http2 extends Component
|
|||||||
*/
|
*/
|
||||||
private function dispatch($domain, $path, $method, $params = [], $timeout = -1, $isUpload = false): mixed
|
private function dispatch($domain, $path, $method, $params = [], $timeout = -1, $isUpload = false): mixed
|
||||||
{
|
{
|
||||||
$client = $this->getClient($domain, $timeout);
|
$ssl = false;
|
||||||
|
if (str_starts_with($domain, 'https://')) {
|
||||||
|
$domain = str_replace('https://', '', $domain);
|
||||||
|
$ssl = true;
|
||||||
|
} else if (str_starts_with($domain, 'http://')) {
|
||||||
|
$domain = str_replace('http://', '', $domain);
|
||||||
|
}
|
||||||
|
|
||||||
|
$client = $this->getClient($domain, $ssl, $timeout);
|
||||||
$request = $this->getRequest($domain, $path, $method, $params, $isUpload);
|
$request = $this->getRequest($domain, $path, $method, $params, $isUpload);
|
||||||
|
|
||||||
$client->send($request);
|
$client->send($request);
|
||||||
@@ -153,6 +160,7 @@ class Http2 extends Component
|
|||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @throws ComponentException
|
* @throws ComponentException
|
||||||
* @throws NotFindClassException
|
* @throws NotFindClassException
|
||||||
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function getRequest($domain, $path, $method, $params, $isUpload = false): Request
|
public function getRequest($domain, $path, $method, $params, $isUpload = false): Request
|
||||||
{
|
{
|
||||||
@@ -187,28 +195,27 @@ class Http2 extends Component
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $domain
|
* @param $domain
|
||||||
|
* @param bool $isSsl
|
||||||
* @param int $timeout
|
* @param int $timeout
|
||||||
* @return H2Client
|
* @return H2Client
|
||||||
* @throws Exception
|
* @throws ComponentException
|
||||||
|
* @throws NotFindClassException
|
||||||
|
* @throws ReflectionException
|
||||||
*/
|
*/
|
||||||
private function getClient($domain, $timeout = -1): H2Client
|
private function getClient($domain, $isSsl = false, $timeout = -1): H2Client
|
||||||
{
|
{
|
||||||
$pool = Snowflake::app()->getChannel();
|
$pool = Snowflake::app()->getChannel();
|
||||||
/** @var H2Client $client */
|
/** @var H2Client $client */
|
||||||
$client = $pool->pop('http2.' . $domain, function () use ($domain, $timeout) {
|
$client = $pool->pop('http2.' . $domain, function () use ($domain, $isSsl, $timeout) {
|
||||||
$domain = rtrim($domain, '/');
|
$domain = rtrim($domain, '/');
|
||||||
|
if (str_contains($domain, ':')) {
|
||||||
$replace = str_replace('https://', '', $domain);
|
[$domain, $port] = explode(':', $domain);
|
||||||
$replace = str_replace('http://', '', $replace);
|
} else if ($isSsl === true) {
|
||||||
|
$port = 443;
|
||||||
if (str_starts_with($domain, 'https')) {
|
|
||||||
$client = new H2Client($replace, 443, true);
|
|
||||||
} else if (str_contains($replace, ':')) {
|
|
||||||
[$host, $port] = explode(':', $replace);
|
|
||||||
$client = new H2Client($host, $port, false);
|
|
||||||
} else {
|
} else {
|
||||||
$client = new H2Client($replace, 80, false);
|
$port = 80;
|
||||||
}
|
}
|
||||||
|
$client = new H2Client($domain, $port, $isSsl);
|
||||||
$client->set([
|
$client->set([
|
||||||
'timeout' => $timeout,
|
'timeout' => $timeout,
|
||||||
'ssl_host_name' => $domain
|
'ssl_host_name' => $domain
|
||||||
|
|||||||
Reference in New Issue
Block a user