Compare commits

...

8 Commits

Author SHA1 Message Date
as2252258 1d9d761798 eee 2025-12-31 00:19:30 +08:00
as2252258 22f425ceb7 ea 2025-11-28 11:43:24 +08:00
as2252258 a52610cf2a ea 2025-11-28 11:39:14 +08:00
as2252258 5697102a85 ea 2025-11-28 11:38:29 +08:00
as2252258 0c0a2fadd5 ea 2025-11-28 11:37:09 +08:00
as2252258 5061a17342 ea 2025-11-28 11:30:07 +08:00
as2252258 9c1bc63f78 ea 2025-11-26 07:52:46 +08:00
as2252258 345af9e727 eee 2025-07-14 15:35:37 +08:00
3 changed files with 191 additions and 188 deletions
+1 -2
View File
@@ -68,10 +68,9 @@ class CoroutineClient extends ClientAbstracts
}
$this->execute($url, $data);
} catch (\Throwable $exception) {
$this->setStatusCode(-1);
$this->setBody(jTraceEx($exception));
$this->setBody(json_encode(['code' => 500, 'message' => $exception->getMessage()]));
}
}
+14 -10
View File
@@ -6,6 +6,7 @@ namespace Kiri;
/**
* Class CurlClient
*
* @package Http\Handler\Client
*/
class CurlClient extends ClientAbstracts
@@ -16,6 +17,7 @@ class CurlClient extends ClientAbstracts
* @param string $method
* @param string $path
* @param array|string $params
*
* @return void
*/
public function request(string $method, string $path, array|string $params = []): void
@@ -37,6 +39,7 @@ class CurlClient extends ClientAbstracts
* @param string $path
* @param string $method
* @param $params
*
* @return void
*/
private function getCurlHandler(string $path, string $method, $params): void
@@ -88,6 +91,7 @@ class CurlClient extends ClientAbstracts
* @param mixed $resource
* @param string $path
* @param string $method
*
* @return void
*/
private function do(mixed $resource, string $path, string $method): void
@@ -134,6 +138,7 @@ class CurlClient extends ClientAbstracts
/**
* @param string $path
*
* @return $this
*/
public function withCAInfo(string $path): static
@@ -155,6 +160,7 @@ class CurlClient extends ClientAbstracts
$this->setStatusCode(curl_errno($this->client));
$this->setBody(curl_error($this->client));
}
$this->close();
}
@@ -186,26 +192,24 @@ class CurlClient extends ClientAbstracts
/**
* @param string $output
*
* @return void
* @throws
*/
private function explode(string $output): void
{
[$header, $body] = explode("\r\n\r\n", $output, 2);
if ($header == 'HTTP/1.1 100 Continue') {
[$header, $body] = explode("\r\n\r\n", $body, 2);
}
// 获取 HTTP 状态码
$statusCode = +curl_getinfo($this->client, CURLINFO_HTTP_CODE);
$header = explode("\r\n", $header);
$status = explode(' ', array_shift($header));
$statusCode = intval($status[1]);
// 获取 header 的大小(不包括最后的 \r\n\r\n 分隔符)
$headerSize = curl_getinfo($this->client, CURLINFO_HEADER_SIZE);
$header = substr($output, 0, $headerSize);
if (in_array($statusCode, [502, 404])) {
$this->retry();
} else {
$this->setStatusCode($statusCode);
$this->setBody($body);
$this->setResponseHeader($header);
$this->setBody(substr($output, $headerSize));
$this->setResponseHeader(explode("\r\n", $header));
}
}
+1 -1
View File
@@ -9,7 +9,7 @@
],
"license": "MIT",
"require": {
"php": ">=8.0",
"php": ">=8.4",
"ext-json": "*",
"ext-swoole": "*"
},