From e691cc0bc280324ffa71bbaf90a6eb63a4f8cb38 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mr=C2=B7x?= Date: Tue, 31 Aug 2021 14:03:26 +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 --- http-server/Message/Response.php | 17 +++++++++++------ http-server/Service/Http.php | 6 +++--- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/http-server/Message/Response.php b/http-server/Message/Response.php index 243ce208..6d8b70eb 100644 --- a/http-server/Message/Response.php +++ b/http-server/Message/Response.php @@ -125,8 +125,10 @@ class Response implements ResponseInterface, \Server\ResponseInterface if (!is_array($data = $this->_toArray($data))) { throw new Exception('Json data format error.'); } - return $this->withBody(new Stream(json_encode($this->_toArray($data)))) - ->withContentType(self::CONTENT_TYPE_JSON); + + $this->stream->write(json_encode($this->_toArray($data))); + + return $this->withContentType(self::CONTENT_TYPE_JSON); } @@ -137,8 +139,9 @@ class Response implements ResponseInterface, \Server\ResponseInterface */ public function html($data): ResponseInterface { - return $this->withBody(new Stream((string)$this->_toArray($data))) - ->withContentType(self::CONTENT_TYPE_HTML); + $this->stream->write((string)$this->_toArray($data)); + + return $this->withContentType(self::CONTENT_TYPE_HTML); } @@ -152,8 +155,10 @@ class Response implements ResponseInterface, \Server\ResponseInterface if (!is_array($data = $this->_toArray($data))) { throw new Exception('Xml data format error.'); } - return $this->withBody(new Stream(Help::toXml($data))) - ->withContentType(self::CONTENT_TYPE_XML); + + $this->stream->write(Help::toXml($data)); + + return $this->withContentType(self::CONTENT_TYPE_XML); } diff --git a/http-server/Service/Http.php b/http-server/Service/Http.php index a07c1848..34919bf7 100644 --- a/http-server/Service/Http.php +++ b/http-server/Service/Http.php @@ -75,11 +75,11 @@ class Http extends \Server\Abstracts\Http implements OnClose, OnConnect $responseData = Help::toXml($responseData); } if (is_array($responseData)) { - $responseData = new Stream(json_encode($responseData, JSON_UNESCAPED_UNICODE)); + $interface->stream->write(json_encode($responseData, JSON_UNESCAPED_UNICODE)); } else { - $responseData = new Stream((string)$responseData); + $interface->stream->write((string)$responseData); } - return $interface->withBody($responseData); + return $interface; }