Skip to content

Commit

Permalink
Merge pull request #168 from eddmann/static-asset-mime-type
Browse files Browse the repository at this point in the history
Handle 'common' web file MIME types
  • Loading branch information
mnapoli authored Jan 17, 2025
2 parents 39508e0 + dc7832a commit 50afe06
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/Http/Middleware/ServeStaticAssets.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,20 @@ public function handle(Request $request, Closure $next)
protected function getMimeType(string $file)
{
$mimeType = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $file);
$mimeType = strstr($mimeType, ';', true);

return str_replace(
['image/vnd.microsoft.icon'],
['image/x-icon'],
$mimeType
);
if ($mimeType === 'image/vnd.microsoft.icon') {
return 'image/x-icon';
}

if ($mimeType !== 'text/plain') {
return $mimeType;
}

return match (pathinfo($file, PATHINFO_EXTENSION)) {
'js' => 'text/javascript',
'css' => 'text/css',
'html' => 'text/html',
default => 'text/plain',
};
}
}

0 comments on commit 50afe06

Please sign in to comment.