Skip to content

Commit

Permalink
Merge pull request #1268 from knedlsepp/fix-mime
Browse files Browse the repository at this point in the history
Fix MIME types when serving .js and .css to fix rendering of HTML reports
  • Loading branch information
dasJ authored Nov 17, 2023
2 parents 33f8a36 + ad99d33 commit 8f48e4d
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/lib/Hydra/Controller/Build.pm
Original file line number Diff line number Diff line change
Expand Up @@ -238,9 +238,17 @@ sub serveFile {
"store", "cat", "--store", getStoreUri(), "$path"]) };

# Detect MIME type.
state $magic = File::LibMagic->new(follow_symlinks => 1);
my $info = $magic->info_from_filename($path);
my $type = $info->{mime_with_encoding};
my $type = "text/plain";
if ($path =~ /.*\.(\S{1,})$/xms) {
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->forward('Hydra::View::Plain');
}
Expand Down

0 comments on commit 8f48e4d

Please sign in to comment.