Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0a54c021b9 | |||
| af9b88f114 |
+33
-1
@@ -9,7 +9,6 @@ use Http\Message\Stream;
|
||||
use JetBrains\PhpStorm\Pure;
|
||||
use Kiri\Context;
|
||||
use Kiri\Core\Help;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Psr\Http\Message\StreamInterface;
|
||||
use Swoole\Coroutine\System;
|
||||
|
||||
@@ -48,6 +47,8 @@ abstract class ClientAbstracts implements IClient
|
||||
private int $port = 80;
|
||||
|
||||
|
||||
private array $_responseHeader = [];
|
||||
|
||||
|
||||
private int $statusCode = 200;
|
||||
|
||||
@@ -63,6 +64,9 @@ abstract class ClientAbstracts implements IClient
|
||||
private int $connect_timeout = 1;
|
||||
|
||||
|
||||
/**
|
||||
* @var resource|\Swoole\Coroutine\Http\Client
|
||||
*/
|
||||
protected mixed $client;
|
||||
|
||||
|
||||
@@ -75,6 +79,34 @@ abstract class ClientAbstracts implements IClient
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getResponseHeaders(): array
|
||||
{
|
||||
return $this->_responseHeader;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param string $key
|
||||
* @return string|int|null
|
||||
*/
|
||||
public function getResponseHeader(string $key): null|string|int
|
||||
{
|
||||
return $this->_responseHeader[$key] ?? null;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $responseHeader
|
||||
*/
|
||||
public function setResponseHeader(array $responseHeader): void
|
||||
{
|
||||
$this->_responseHeader = $responseHeader;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param int $statusCode
|
||||
*/
|
||||
|
||||
@@ -53,6 +53,7 @@ class CoroutineClient extends ClientAbstracts
|
||||
}
|
||||
$this->setStatusCode($this->client->getStatusCode());
|
||||
$this->setBody($this->client->getBody());
|
||||
$this->setResponseHeader($this->client->headers);
|
||||
} catch (\Throwable $exception) {
|
||||
Kiri::getDi()->get(Logger::class)->error('rpc', [$exception]);
|
||||
$this->setStatusCode(-1);
|
||||
|
||||
@@ -172,6 +172,7 @@ class Curl extends ClientAbstracts
|
||||
|
||||
$this->setStatusCode(intval($status[1]));
|
||||
$this->setBody($body);
|
||||
$this->setResponseHeader($header);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user