eee
This commit is contained in:
+42
-14
@@ -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
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user