From af9b88f114d02f8ffb9ecff4d155204dc719f1c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Mon, 29 Nov 2021 11:50:28 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ClientAbstracts.php | 24 ++++++++++++++++++++++++ src/CoroutineClient.php | 1 + src/Curl.php | 1 + 3 files changed, 26 insertions(+) diff --git a/src/ClientAbstracts.php b/src/ClientAbstracts.php index a41a7b7..e4d6f6f 100644 --- a/src/ClientAbstracts.php +++ b/src/ClientAbstracts.php @@ -49,6 +49,9 @@ abstract class ClientAbstracts implements IClient + private array $_responseHeader = []; + + private int $statusCode = 200; @@ -63,6 +66,9 @@ abstract class ClientAbstracts implements IClient private int $connect_timeout = 1; + /** + * @var resource|\Swoole\Coroutine\Http\Client + */ protected mixed $client; @@ -75,6 +81,24 @@ abstract class ClientAbstracts implements IClient } + /** + * @return array + */ + public function getResponseHeader(): array + { + return $this->_responseHeader; + } + + + /** + * @param array $responseHeader + */ + public function setResponseHeader(array $responseHeader): void + { + $this->_responseHeader = $responseHeader; + } + + /** * @param int $statusCode */ diff --git a/src/CoroutineClient.php b/src/CoroutineClient.php index 6743af8..80ec51c 100644 --- a/src/CoroutineClient.php +++ b/src/CoroutineClient.php @@ -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); diff --git a/src/Curl.php b/src/Curl.php index e6816fa..2d39174 100644 --- a/src/Curl.php +++ b/src/Curl.php @@ -172,6 +172,7 @@ class Curl extends ClientAbstracts $this->setStatusCode(intval($status[1])); $this->setBody($body); + $this->setResponseHeader($header); } /**