Switch default charset to UTF-8 again.
This commit is contained in:
parent
ce855061ec
commit
77ab1e7f9f
1 changed files with 19 additions and 7 deletions
|
@ -22,18 +22,28 @@ class HttpRouter implements IRouter {
|
|||
|
||||
private array $contentHandlers = [];
|
||||
|
||||
private string $defaultCharSet;
|
||||
|
||||
private IErrorHandler $errorHandler;
|
||||
|
||||
public function __construct(
|
||||
string $charSet = '',
|
||||
IErrorHandler|string $errorHandler = 'html',
|
||||
bool $registerDefaultContentHandlers = true,
|
||||
) {
|
||||
$this->defaultCharSet = $charSet;
|
||||
$this->setErrorHandler($errorHandler);
|
||||
|
||||
if($registerDefaultContentHandlers)
|
||||
$this->registerDefaultContentHandlers();
|
||||
}
|
||||
|
||||
public function getCharSet(): string {
|
||||
if($this->defaultCharSet === '')
|
||||
return strtolower(mb_preferred_mime_name(mb_internal_encoding()));
|
||||
return $this->defaultCharSet;
|
||||
}
|
||||
|
||||
public function getErrorHandler(): IErrorHandler {
|
||||
return $this->errorHandler;
|
||||
}
|
||||
|
@ -191,14 +201,16 @@ class HttpRouter implements IRouter {
|
|||
$response->setContent(new StringContent($result));
|
||||
|
||||
if(!$response->hasContentType()) {
|
||||
$charset = strtolower(mb_preferred_mime_name(mb_detect_encoding($result)));
|
||||
|
||||
if(strtolower(substr($result, 0, 14)) === '<!doctype html')
|
||||
$response->setTypeHTML($charset);
|
||||
elseif(strtolower(substr($result, 0, 5)) === '<?xml')
|
||||
$response->setTypeXML($charset);
|
||||
else
|
||||
$response->setTypePlain($charset);
|
||||
$response->setTypeHTML($this->getCharSet());
|
||||
else {
|
||||
$charset = strtolower(mb_preferred_mime_name(mb_detect_encoding($result)));
|
||||
|
||||
if(strtolower(substr($result, 0, 5)) === '<?xml')
|
||||
$response->setTypeXML($charset);
|
||||
else
|
||||
$response->setTypePlain($charset);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue