This commit is contained in:
as2252258@163.com
2021-09-21 02:46:21 +08:00
parent 0c4af841dd
commit 907942b01a
11 changed files with 404 additions and 378 deletions
+21 -4
View File
@@ -19,7 +19,10 @@ class Response implements ResponseInterface
use Message;
const CONTENT_TYPE_HTML = 'text/html;charset=utf-8';
const CONTENT_TYPE_HTML = 'text/html';
protected string $charset = 'utf8';
protected int $statusCode = 200;
@@ -148,7 +151,7 @@ class Response implements ResponseInterface
* @param string $contentType
* @return static
*/
public function json($data, string $contentType = 'application/json;charset=utf-8'): static
public function json($data, string $contentType = 'application/json'): static
{
$this->stream->write(json_encode($data));
@@ -161,7 +164,7 @@ class Response implements ResponseInterface
* @param string $contentType
* @return static
*/
public function html($data, string $contentType = 'text/html;charset=utf-8'): static
public function html($data, string $contentType = 'text/html'): static
{
if (!is_string($data)) {
$data = json_encode($data);
@@ -178,7 +181,7 @@ class Response implements ResponseInterface
* @param string $contentType
* @return static
*/
public function xml($data, string $contentType = 'application/xml;charset=utf-8'): static
public function xml($data, string $contentType = 'application/xml'): static
{
$this->stream->write(Help::toXml($data));
@@ -186,6 +189,20 @@ class Response implements ResponseInterface
}
/**
* @param string $charset
* @return $this
*/
public function withCharset(string $charset): static
{
$type = explode('charset', $this->getContentType())[0];
$this->withContentType(
rtrim($type,';') . ';charset=' . $charset
);
return $this;
}
/**
* @param $path
* @param bool $isChunk