Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 1d9d761798 | |||
| 22f425ceb7 | |||
| a52610cf2a | |||
| 5697102a85 | |||
| 0c0a2fadd5 | |||
| 5061a17342 | |||
| 9c1bc63f78 | |||
| 345af9e727 |
+1
-2
@@ -68,10 +68,9 @@ class CoroutineClient extends ClientAbstracts
|
|||||||
}
|
}
|
||||||
|
|
||||||
$this->execute($url, $data);
|
$this->execute($url, $data);
|
||||||
|
|
||||||
} catch (\Throwable $exception) {
|
} catch (\Throwable $exception) {
|
||||||
$this->setStatusCode(-1);
|
$this->setStatusCode(-1);
|
||||||
$this->setBody(jTraceEx($exception));
|
$this->setBody(json_encode(['code' => 500, 'message' => $exception->getMessage()]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+14
-10
@@ -6,6 +6,7 @@ namespace Kiri;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Class CurlClient
|
* Class CurlClient
|
||||||
|
*
|
||||||
* @package Http\Handler\Client
|
* @package Http\Handler\Client
|
||||||
*/
|
*/
|
||||||
class CurlClient extends ClientAbstracts
|
class CurlClient extends ClientAbstracts
|
||||||
@@ -16,6 +17,7 @@ class CurlClient extends ClientAbstracts
|
|||||||
* @param string $method
|
* @param string $method
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param array|string $params
|
* @param array|string $params
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function request(string $method, string $path, array|string $params = []): 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 $path
|
||||||
* @param string $method
|
* @param string $method
|
||||||
* @param $params
|
* @param $params
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function getCurlHandler(string $path, string $method, $params): void
|
private function getCurlHandler(string $path, string $method, $params): void
|
||||||
@@ -88,6 +91,7 @@ class CurlClient extends ClientAbstracts
|
|||||||
* @param mixed $resource
|
* @param mixed $resource
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param string $method
|
* @param string $method
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private function do(mixed $resource, string $path, string $method): void
|
private function do(mixed $resource, string $path, string $method): void
|
||||||
@@ -134,6 +138,7 @@ class CurlClient extends ClientAbstracts
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $path
|
* @param string $path
|
||||||
|
*
|
||||||
* @return $this
|
* @return $this
|
||||||
*/
|
*/
|
||||||
public function withCAInfo(string $path): static
|
public function withCAInfo(string $path): static
|
||||||
@@ -155,6 +160,7 @@ class CurlClient extends ClientAbstracts
|
|||||||
$this->setStatusCode(curl_errno($this->client));
|
$this->setStatusCode(curl_errno($this->client));
|
||||||
$this->setBody(curl_error($this->client));
|
$this->setBody(curl_error($this->client));
|
||||||
}
|
}
|
||||||
|
$this->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -186,26 +192,24 @@ class CurlClient extends ClientAbstracts
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @param string $output
|
* @param string $output
|
||||||
|
*
|
||||||
* @return void
|
* @return void
|
||||||
* @throws
|
* @throws
|
||||||
*/
|
*/
|
||||||
private function explode(string $output): void
|
private function explode(string $output): void
|
||||||
{
|
{
|
||||||
[$header, $body] = explode("\r\n\r\n", $output, 2);
|
// 获取 HTTP 状态码
|
||||||
if ($header == 'HTTP/1.1 100 Continue') {
|
$statusCode = +curl_getinfo($this->client, CURLINFO_HTTP_CODE);
|
||||||
[$header, $body] = explode("\r\n\r\n", $body, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
$header = explode("\r\n", $header);
|
// 获取 header 的大小(不包括最后的 \r\n\r\n 分隔符)
|
||||||
$status = explode(' ', array_shift($header));
|
$headerSize = curl_getinfo($this->client, CURLINFO_HEADER_SIZE);
|
||||||
|
$header = substr($output, 0, $headerSize);
|
||||||
$statusCode = intval($status[1]);
|
|
||||||
if (in_array($statusCode, [502, 404])) {
|
if (in_array($statusCode, [502, 404])) {
|
||||||
$this->retry();
|
$this->retry();
|
||||||
} else {
|
} else {
|
||||||
$this->setStatusCode($statusCode);
|
$this->setStatusCode($statusCode);
|
||||||
$this->setBody($body);
|
$this->setBody(substr($output, $headerSize));
|
||||||
$this->setResponseHeader($header);
|
$this->setResponseHeader(explode("\r\n", $header));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -9,7 +9,7 @@
|
|||||||
],
|
],
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"require": {
|
"require": {
|
||||||
"php": ">=8.0",
|
"php": ">=8.4",
|
||||||
"ext-json": "*",
|
"ext-json": "*",
|
||||||
"ext-swoole": "*"
|
"ext-swoole": "*"
|
||||||
},
|
},
|
||||||
|
|||||||
Reference in New Issue
Block a user