This commit is contained in:
2023-10-27 22:23:11 +08:00
parent 165f62113c
commit 7b14fa075e
3 changed files with 677 additions and 638 deletions
+42 -14
View File
@@ -25,35 +25,23 @@ abstract class ClientAbstracts implements IClient
const PUT = 'put';
private string $host = '';
private array $header = [];
private int $timeout = 0;
private string $method = 'get';
private bool $isSSL = FALSE;
private string $agent = '';
private string $ssl_cert_file = '';
private string $ssl_key_file = '';
private string $ca = '';
private int $port = 80;
protected int $num = 0;
private ?array $_responseHeader = [];
private int $statusCode = 200;
protected int $retryNum = 0;
protected int $retryTimeout = 0;
private bool $verifyPeer = TRUE;
private string $proxyHost = '';
private int $proxyPort = 0;
/**
@@ -84,6 +72,46 @@ abstract class ClientAbstracts implements IClient
}
/**
* @return string
*/
public function getProxyHost(): string
{
return $this->proxyHost;
}
/**
* @return string
*/
public function getProxyPort(): string
{
return $this->proxyPort;
}
/**
* @param string $proxy
* @return ClientAbstracts
*/
public function withProxyHost(string $proxy): static
{
$this->proxyHost = $proxy;
return $this;
}
/**
* @param int $proxy
* @return ClientAbstracts
*/
public function withProxyPort(int $proxy): static
{
$this->proxyPort = $proxy;
return $this;
}
/**
* @param int $retryTimeout
* @return $this
+5
View File
@@ -115,6 +115,11 @@ class CurlClient extends ClientAbstracts
if ($method === self::POST || $method == self::UPLOAD) {
curl_setopt($resource, CURLOPT_POST, 1);
}
[$proxy, $port] = [$this->getProxyHost(), $this->getProxyPort()];
if (!empty($proxy) && $port > 0) {
curl_setopt($resource, CURLOPT_PROXYPORT, $port);
curl_setopt($resource, CURLOPT_PROXY, $proxy);
}
curl_setopt($resource, CURLOPT_CUSTOMREQUEST, strtoupper($method));
$this->client = $resource;
if (!empty($this->caPath)) {
+6
View File
@@ -19,6 +19,12 @@ trait TSwooleClient
if ($this->getConnectTimeout() > 0) {
$params['timeout'] = $this->getConnectTimeout();
}
[$proxy, $port] = [$this->getProxyHost(), $this->getProxyPort()];
if (!empty($proxy) && $port > 0) {
$params['http_proxy_host'] = $proxy;
$params['http_proxy_port'] = $port;
}
if (empty($sslCert) || empty($sslKey) || empty($sslCa)) {
return $params;
}