This commit is contained in:
2021-08-03 10:50:07 +08:00
parent 1dfd429211
commit 489ba0917f
+12 -6
View File
@@ -15,7 +15,6 @@ use HttpServer\Http\Formatter\HtmlFormatter;
use HttpServer\Http\Formatter\JsonFormatter;
use HttpServer\Http\Formatter\XmlFormatter;
use HttpServer\IInterface\IFormatter;
use JetBrains\PhpStorm\Pure;
use Snowflake\Core\Help;
use Snowflake\Snowflake;
use Swoole\Http\Response as SResponse;
@@ -56,7 +55,15 @@ class Response extends HttpService
*/
public function setFormat($format): static
{
$this->format = $format;
/** @var SResponse $response */
$response = Context::getContext(SResponse::class);
if ($format == self::HTML) {
$response->header('Content-Type', 'text/html;charset=utf-8');
} else if ($format == self::XML) {
$response->header('Content-Type', 'application/xml;charset=utf-8');
} else {
$response->header('Content-Type', 'application/json;charset=utf-8');
}
return $this;
}
@@ -79,7 +86,7 @@ class Response extends HttpService
/** @var SResponse $response */
$response = Context::getContext(SResponse::class);
$response->header('Content-Type','text/html;charset=utf-8');
$response->header('Content-Type', 'text/html;charset=utf-8');
return (string)$content;
}
@@ -95,7 +102,7 @@ class Response extends HttpService
/** @var SResponse $response */
$response = Context::getContext(SResponse::class);
$response->header('Content-Type','application/json;charset=utf-8');
$response->header('Content-Type', 'application/json;charset=utf-8');
return json_encode($content, JSON_UNESCAPED_UNICODE);
}
@@ -111,7 +118,7 @@ class Response extends HttpService
/** @var SResponse $response */
$response = Context::getContext(SResponse::class);
$response->header('Content-Type','application/xml;charset=utf-8');
$response->header('Content-Type', 'application/xml;charset=utf-8');
return $content;
}
@@ -235,7 +242,6 @@ class Response extends HttpService
}
/**
* @param $url
* @param array $param