This commit is contained in:
2021-09-06 18:29:04 +08:00
parent c8d915b5e8
commit f6e8d102ec
2 changed files with 23 additions and 13 deletions
+18 -6
View File
@@ -43,16 +43,28 @@ class Response implements ResponseInterface, \Server\ResponseInterface
*/
public function withContentType(string $type): static
{
if (!in_array($type, [
Response::CONTENT_TYPE_HTML, Response::CONTENT_TYPE_JSON,
Response::CONTENT_TYPE_STREAM, Response::CONTENT_TYPE_XML
])) {
throw new Exception('Wrong content type.');
}
return $this->withHeader('Content-Type', $type);
}
/**
* @return bool
*/
#[Pure] public function hasContentType(): bool
{
return $this->hasHeader('Content-Type');
}
/**
* @return string
*/
#[Pure] public function getContentType(): string
{
return $this->getHeaderLine('Content-Type');
}
/**
* @return int
*/