From b92ab0bf1ddd26b256c96f65e9908743adbe5358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Tue, 11 Jan 2022 15:24:22 +0800 Subject: [PATCH] =?UTF-8?q?Revert=20"=E6=94=B9=E5=90=8D"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit fdf58326 --- AsyncClient.php | 51 ++++++++++++++++++++++++++++++++++--------------- 1 file changed, 36 insertions(+), 15 deletions(-) diff --git a/AsyncClient.php b/AsyncClient.php index d55b509..d6219a7 100644 --- a/AsyncClient.php +++ b/AsyncClient.php @@ -10,6 +10,7 @@ declare(strict_types=1); namespace Kiri; use Exception; +use JetBrains\PhpStorm\Pure; use Kiri\Abstracts\Logger; use Kiri\Exception\ConfigException; use Kiri\Message\Stream; @@ -107,22 +108,10 @@ class AsyncClient extends ClientAbstracts */ private function execute(string $path, string $content) { - $array = []; - $array[] = strtoupper($this->getMethod()) . ' ' . $path . ' HTTP/1.1'; - if (!empty($this->getHeader())) { - foreach ($this->getHeader() as $key => $value) { - $array[] = sprintf('%s: %s', $key, $value); - } - } + $array = $this->_parseHeaders($path); + $this->client->send(implode("\r\n", $array) . "\r\n\r\n" . $content); - $receive = ''; - while (true) { - $_tmp = $this->client->recv(); - if (empty($_tmp)) { - break; - } - $receive .= $_tmp; - } + $receive = $this->waite(''); Kiri::getDi()->get(Logger::class)->debug($receive); @@ -137,6 +126,38 @@ class AsyncClient extends ClientAbstracts } + /** + * @param string $path + * @return array + */ + #[Pure] private function _parseHeaders(string $path): array + { + $array = []; + $array[] = strtoupper($this->getMethod()) . ' ' . $path . ' HTTP/1.1'; + if (!empty($this->getHeader())) { + foreach ($this->getHeader() as $key => $value) { + $array[] = sprintf('%s: %s', $key, $value); + } + } + return $array; + } + + + /** + * @param $string + * @return mixed + */ + private function waite($string): mixed + { + $tmp = $this->client->recv(); + if (empty($tmp)) { + return $string; + } + $string .= $tmp; + return $this->waite($string); + } + + private function chunked() {