Merge pull request #1268 from knedlsepp/fix-mime

Fix MIME types when serving .js and .css to fix rendering of HTML reports
This commit is contained in:
Janne Heß 2023-11-17 22:16:27 +01:00 committed by GitHub
commit 8f48e4ddec
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -238,9 +238,17 @@ sub serveFile {
"store", "cat", "--store", getStoreUri(), "$path"]) }; "store", "cat", "--store", getStoreUri(), "$path"]) };
# Detect MIME type. # Detect MIME type.
state $magic = File::LibMagic->new(follow_symlinks => 1); my $type = "text/plain";
my $info = $magic->info_from_filename($path); if ($path =~ /.*\.(\S{1,})$/xms) {
my $type = $info->{mime_with_encoding}; my $ext = $1;
my $mimeTypes = MIME::Types->new(only_complete => 1);
my $t = $mimeTypes->mimeTypeOf($ext);
$type = ref $t ? $t->type : $t if $t;
} else {
state $magic = File::LibMagic->new(follow_symlinks => 1);
my $info = $magic->info_from_filename($path);
$type = $info->{mime_with_encoding};
}
$c->response->content_type($type); $c->response->content_type($type);
$c->forward('Hydra::View::Plain'); $c->forward('Hydra::View::Plain');
} }