Skip to content

Commit 50afe06

Browse files
authored
Merge pull request #168 from eddmann/static-asset-mime-type
Handle 'common' web file MIME types
2 parents 39508e0 + dc7832a commit 50afe06

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

src/Http/Middleware/ServeStaticAssets.php

+14-6
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,20 @@ public function handle(Request $request, Closure $next)
4343
protected function getMimeType(string $file)
4444
{
4545
$mimeType = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $file);
46-
$mimeType = strstr($mimeType, ';', true);
4746

48-
return str_replace(
49-
['image/vnd.microsoft.icon'],
50-
['image/x-icon'],
51-
$mimeType
52-
);
47+
if ($mimeType === 'image/vnd.microsoft.icon') {
48+
return 'image/x-icon';
49+
}
50+
51+
if ($mimeType !== 'text/plain') {
52+
return $mimeType;
53+
}
54+
55+
return match (pathinfo($file, PATHINFO_EXTENSION)) {
56+
'js' => 'text/javascript',
57+
'css' => 'text/css',
58+
'html' => 'text/html',
59+
default => 'text/plain',
60+
};
5361
}
5462
}

0 commit comments

Comments
 (0)