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