Compare commits

...

2 Commits

Author SHA1 Message Date
as2252258 0a54c021b9 改名 2021-11-29 11:51:19 +08:00
as2252258 af9b88f114 改名 2021-11-29 11:50:28 +08:00
3 changed files with 35 additions and 1 deletions
+33 -1
View File
@@ -9,7 +9,6 @@ use Http\Message\Stream;
use JetBrains\PhpStorm\Pure; use JetBrains\PhpStorm\Pure;
use Kiri\Context; use Kiri\Context;
use Kiri\Core\Help; use Kiri\Core\Help;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\StreamInterface; use Psr\Http\Message\StreamInterface;
use Swoole\Coroutine\System; use Swoole\Coroutine\System;
@@ -48,6 +47,8 @@ abstract class ClientAbstracts implements IClient
private int $port = 80; private int $port = 80;
private array $_responseHeader = [];
private int $statusCode = 200; private int $statusCode = 200;
@@ -63,6 +64,9 @@ abstract class ClientAbstracts implements IClient
private int $connect_timeout = 1; private int $connect_timeout = 1;
/**
* @var resource|\Swoole\Coroutine\Http\Client
*/
protected mixed $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 * @param int $statusCode
*/ */
+1
View File
@@ -53,6 +53,7 @@ class CoroutineClient extends ClientAbstracts
} }
$this->setStatusCode($this->client->getStatusCode()); $this->setStatusCode($this->client->getStatusCode());
$this->setBody($this->client->getBody()); $this->setBody($this->client->getBody());
$this->setResponseHeader($this->client->headers);
} catch (\Throwable $exception) { } catch (\Throwable $exception) {
Kiri::getDi()->get(Logger::class)->error('rpc', [$exception]); Kiri::getDi()->get(Logger::class)->error('rpc', [$exception]);
$this->setStatusCode(-1); $this->setStatusCode(-1);
+1
View File
@@ -172,6 +172,7 @@ class Curl extends ClientAbstracts
$this->setStatusCode(intval($status[1])); $this->setStatusCode(intval($status[1]));
$this->setBody($body); $this->setBody($body);
$this->setResponseHeader($header);
} }
/** /**