forked from lix-project/hydra
Detect MIME type
This commit is contained in:
parent
42fbde0383
commit
30943dd217
|
@ -14,6 +14,7 @@ use Nix::Store;
|
||||||
use Nix::Config;
|
use Nix::Config;
|
||||||
use List::MoreUtils qw(all);
|
use List::MoreUtils qw(all);
|
||||||
use Encode;
|
use Encode;
|
||||||
|
use MIME::Types;
|
||||||
|
|
||||||
|
|
||||||
sub buildChain :Chained('/') :PathPart('build') :CaptureArgs(1) {
|
sub buildChain :Chained('/') :PathPart('build') :CaptureArgs(1) {
|
||||||
|
@ -242,7 +243,15 @@ sub download : Chained('buildChain') PathPart {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
$c->stash->{'plain'} = { data => readNixFile($path) };
|
$c->stash->{'plain'} = { data => readNixFile($path) };
|
||||||
$c->response->content_type('application/octet-stream');
|
# Detect MIME type. Borrowed from Catalyst::Plugin::Static::Simple.
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
$c->response->content_type($type);
|
||||||
$c->forward('Hydra::View::Plain');
|
$c->forward('Hydra::View::Plain');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue