modify plugin name
This commit is contained in:
+8
-39
@@ -5,10 +5,10 @@ namespace Kiri;
|
||||
|
||||
|
||||
use Closure;
|
||||
use Kiri\Message\Stream;
|
||||
use Exception;
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
use Kiri\Context;
|
||||
use Kiri\Core\Help;
|
||||
use Kiri\Message\Stream;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Swoole\Coroutine\System;
|
||||
|
||||
@@ -285,11 +285,14 @@ abstract class ClientAbstracts implements IClient
|
||||
private function withHost(string $host): static
|
||||
{
|
||||
$this->host = $host;
|
||||
if (!preg_match('/(\d{1,3}\.){3}\d{1,3}/', $host)) {
|
||||
if (Context::inCoroutine()) {
|
||||
$this->host = System::gethostbyname($host);
|
||||
}
|
||||
return $this->withAddedHeader('Host', $host);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
@@ -638,6 +641,7 @@ abstract class ClientAbstracts implements IClient
|
||||
* @param $data
|
||||
* @param $body
|
||||
* @return array|string|null
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function resolve($data, $body): array|string|null
|
||||
{
|
||||
@@ -713,44 +717,9 @@ abstract class ClientAbstracts implements IClient
|
||||
* @param string $string
|
||||
* @return array
|
||||
*/
|
||||
protected function matchHost(string $string): array
|
||||
#[Pure] protected function matchHost(string $string): array
|
||||
{
|
||||
if (($parse = isUrl($string, TRUE)) === FALSE) {
|
||||
return $this->defaultString($string);
|
||||
}
|
||||
[$isHttps, $domain, $port, $path] = $parse;
|
||||
if (str_contains($domain, ':' . $port)) {
|
||||
$domain = str_replace(':' . $port, '', $domain);
|
||||
}
|
||||
$this->port = $isHttps ? 443 : $this->port;
|
||||
if (isIp($domain)) {
|
||||
$this->host = $domain;
|
||||
} else if (Context::inCoroutine()) {
|
||||
$this->host = System::gethostbyname($domain) ?? $domain;
|
||||
} else {
|
||||
$this->host = $domain;
|
||||
}
|
||||
$this->header['Host'] = $domain;
|
||||
if (!str_starts_with($path, '/')) {
|
||||
$path = '/' . $path;
|
||||
}
|
||||
return [$this->host, $isHttps, $path];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param $string
|
||||
* @return array
|
||||
*/
|
||||
private function defaultString($string): array
|
||||
{
|
||||
$host = $this->getHost();
|
||||
if ($string == '/') {
|
||||
$string = '/';
|
||||
} else if (!str_starts_with($string, '/')) {
|
||||
$string = '/' . $string;
|
||||
}
|
||||
return [$host, $this->isSSL(), $string];
|
||||
return [$this->host, $this->isSSL(), $string];
|
||||
}
|
||||
|
||||
|
||||
|
||||
+4
-3
@@ -10,9 +10,8 @@ declare(strict_types=1);
|
||||
namespace Kiri;
|
||||
|
||||
use Exception;
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
use Kiri\Abstracts\Logger;
|
||||
use Kiri;
|
||||
use Kiri\Abstracts\Logger;
|
||||
use Swoole\Coroutine\Http\Client as SwowClient;
|
||||
|
||||
/**
|
||||
@@ -33,6 +32,9 @@ class CoroutineClient extends ClientAbstracts
|
||||
*/
|
||||
public function request(string $method, $path, array $params = []): void
|
||||
{
|
||||
if (!str_starts_with($path, '/')) {
|
||||
$path = '/' . $path;
|
||||
}
|
||||
$this->withMethod($method)
|
||||
->coroutine(
|
||||
$this->matchHost($path),
|
||||
@@ -41,7 +43,6 @@ class CoroutineClient extends ClientAbstracts
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @return $this
|
||||
|
||||
+6
-8
@@ -5,10 +5,7 @@ namespace Kiri;
|
||||
|
||||
|
||||
use Exception;
|
||||
use Kiri\Message\Response;
|
||||
use Kiri\Message\Stream;
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
|
||||
/**
|
||||
@@ -26,6 +23,9 @@ class CurlClient extends ClientAbstracts
|
||||
*/
|
||||
public function request($method, $path, array $params = []): void
|
||||
{
|
||||
if (!str_starts_with($path, '/')) {
|
||||
$path = '/' . $path;
|
||||
}
|
||||
if ($method == self::GET) {
|
||||
$path = $this->joinGetParams($path, $params);
|
||||
}
|
||||
@@ -44,14 +44,12 @@ class CurlClient extends ClientAbstracts
|
||||
*/
|
||||
private function getCurlHandler($path, $method, $params): void
|
||||
{
|
||||
[$host, $isHttps, $path] = $this->matchHost($path);
|
||||
|
||||
$host = $isHttps ? 'https://' . $host : 'http://' . $host;
|
||||
$host = $this->isSSL() ? 'https://' . $this->getHost() : 'http://' . $this->getHost();
|
||||
if ($this->getPort() != 443 && $this->getPort() != 80) {
|
||||
$host .= ':' . $this->getPort();
|
||||
}
|
||||
$this->do(curl_init($host . $path), $host . $path, $method);
|
||||
if ($isHttps !== FALSE) {
|
||||
if ($this->isSSL()) {
|
||||
$this->curlHandlerSslSet();
|
||||
}
|
||||
$contents = $this->getData()->getContents();
|
||||
@@ -115,7 +113,7 @@ class CurlClient extends ClientAbstracts
|
||||
curl_setopt($resource, CURLOPT_CUSTOMREQUEST, strtoupper($method));
|
||||
$this->client = $resource;
|
||||
if (!empty($this->caPath)) {
|
||||
curl_setopt($this->client,CURLOPT_CAINFO, $this->caPath);
|
||||
curl_setopt($this->client, CURLOPT_CAINFO, $this->caPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user