This commit is contained in:
2026-06-12 23:57:21 +08:00
parent 1d9d761798
commit 7bcb789ed2
6 changed files with 698 additions and 785 deletions
+14 -14
View File
@@ -34,7 +34,7 @@ class CoroutineClient extends ClientAbstracts
$path = '/' . $path;
}
$host = $this->getHost();
$host = $this->host;
if (!preg_match('/(\d{1,3}\.){3}\d{1,3}/', $host)) {
$this->withAddedHeader('Host', $host);
}
@@ -62,15 +62,15 @@ class CoroutineClient extends ClientAbstracts
private function coroutine(string $url, array|string $data = []): void
{
try {
$this->generate_client($this->getHost(), $this->isSSL());
$this->generate_client($this->host, $this->isSSL);
if ($this->client->statusCode < 0) {
throw new Exception($this->client->errMsg);
}
$this->execute($url, $data);
} catch (\Throwable $exception) {
$this->setStatusCode(-1);
$this->setBody(json_encode(['code' => 500, 'message' => $exception->getMessage()]));
$this->statusCode = -1;
$this->body = json_encode(['code' => 500, 'message' => $exception->getMessage()]);
}
}
@@ -86,8 +86,8 @@ class CoroutineClient extends ClientAbstracts
if (in_array($this->client->getStatusCode(), [502, 404])) {
$this->retry($path, $data);
} else {
$this->setStatusCode($this->client->getStatusCode());
$this->setBody($this->client->getBody());
$this->statusCode = $this->client->getStatusCode();
$this->body = $this->client->getBody();
$this->setResponseHeader($this->client->headers);
}
}
@@ -105,8 +105,8 @@ class CoroutineClient extends ClientAbstracts
$this->execute($path, $data);
} else {
$this->setStatusCode($this->client->statusCode);
$this->setBody($this->client->errMsg);
$this->statusCode = $this->client->statusCode;
$this->body = $this->client->errMsg;
}
}
@@ -116,17 +116,17 @@ class CoroutineClient extends ClientAbstracts
*/
private function generate_client(string $host, bool $isHttps): void
{
if ($isHttps || $this->isSSL()) {
if ($isHttps || $this->isSSL) {
$this->client = new SwowClient($host, 443, true);
} else {
$this->client = new SwowClient($host, $this->getPort(), false);
}
$this->client->set($this->settings());
if (!empty($this->getAgent())) {
$this->withAddedHeader('User-Agent', $this->getAgent());
if (!empty($this->agent)) {
$this->withAddedHeader('User-Agent', $this->agent);
}
$this->client->setHeaders($this->getHeader());
$this->client->setMethod(strtoupper($this->getMethod()));
$this->client->setHeaders($this->header);
$this->client->setMethod(strtoupper($this->method));
}
@@ -137,7 +137,7 @@ class CoroutineClient extends ClientAbstracts
*/
private function setParams(string $path, mixed $data): string
{
$content = $this->getData();
$content = $this->_data;
if (!empty($content)) {
$this->client->setData($content);
}