Always use UTF-8 for HTML if no content type is specified.

This commit is contained in:
flash 2023-11-20 19:01:19 +00:00
parent c563bb20e8
commit e31781c69f
2 changed files with 11 additions and 9 deletions

View file

@ -1 +1 @@
0.2311.91403
0.2311.201900

View file

@ -1,7 +1,7 @@
<?php
// HttpFx.php
// Created: 2022-02-15
// Updated: 2023-11-09
// Updated: 2023-11-20
namespace Index\Http;
@ -126,14 +126,16 @@ class HttpFx implements IRouter {
$responseBuilder->setContent(new StringContent($result));
if(!$responseBuilder->hasContentType()) {
$charset = strtolower(mb_preferred_mime_name(mb_detect_encoding($result)));
if(strtolower(substr($result, 0, 14)) === '<!doctype html')
$responseBuilder->setTypeHTML('utf-8');
else {
$charset = strtolower(mb_preferred_mime_name(mb_detect_encoding($result)));
if(strtolower(substr($result, 0, 5)) === '<?xml')
$responseBuilder->setTypeXML($charset);
elseif(strtolower(substr($result, 0, 14)) === '<!doctype html')
$responseBuilder->setTypeHTML($charset);
else
$responseBuilder->setTypePlain($charset);
if(strtolower(substr($result, 0, 5)) === '<?xml')
$responseBuilder->setTypeXML($charset);
else
$responseBuilder->setTypePlain($charset);
}
}
}
}