MIME_CONTENT_TYPE — Detect the MIME type implementation of the file, replace it with an implementation based on MIME-Type Detection League/MIME-Type-detection
1. Reference:The same CSS file (their ETags are equal), due to the difference in the response’s content-type, leads to the difference in the interface of the web page. Discover the response’s Content-Type based on MIME_CONTENT_TYPE – the MIME type of the detection file, and finally based on the MIME-TYPE detection LEAGUE/MIME-TYPE-detection League/mime-type-detection implementation. Detect according to content, and fall back to by Extension Detection. as shown in Figure 1
use League\MimeTypeDetection\ExtensionMimeTypeDetector;
$this->detector = new ExtensionMimeTypeDetector();
Log::info(
$return['asset_key'],
[
$return['asset_key'],
$this->detector->detectMimeTypeFromPath($fullPath),
]
);
[2023-05-18 14:00:04] local.INFO: apps/internal/code-display/blocks/code-display.blade.php [
"apps/internal/code-display/blocks/code-display.blade.php",
"application/x-httpd-php"
]
[2023-05-18 14:00:04] local.INFO: apps/internal/comment/.env.local [
"apps/internal/comment/.env.local",
null
]
[2023-05-18 14:00:04] local.INFO: apps/internal/comment/app.json [
"apps/internal/comment/app.json",
"application/json"
]
[2023-05-18 14:00:04] local.INFO: apps/internal/comment/assets/app.6e10b7.css [
"apps/internal/comment/assets/app.6e10b7.css",
"text/css"
]
[2023-05-18 14:00:04] local.INFO: apps/internal/comment/assets/app.f8ed5d.js [
"apps/internal/comment/assets/app.f8ed5d.js",
"application/javascript"
]
[2023-05-18 14:00:05] local.INFO: apps/internal/custom-button/assets/images/ali-express-large.8fdc24.png [
"apps/internal/custom-button/assets/images/ali-express-large.8fdc24.png",
"image/png"
]
[2023-05-18 14:00:07] local.INFO: apps/internal/sharing-incentives/assets/images/sparkles.a0d182.jpg [
"apps/internal/sharing-incentives/assets/images/sparkles.a0d182.jpg",
"image/jpeg"
]
2. Check the generated Content-Type, which is in line with expectations. NULL is returned when the corresponding extension does not exist. At this time, it needs to be retracted.
Log::info(
$return['asset_key'],
[
$return['asset_key'],
$this->detector->detectMimeTypeFromPath($fullPath) ?? mime_content_type($fullPath),
]
);
