<%init>

my $file = $m->base_comp->source_file;

if ($file =~ /\.(gif|png|jpe?g)$/i) {
    #&RT::Interface::Web::StaticFileHeaders();
    my $type = "image/$1";
    $type =~ s/jpg/jpeg/gi;

    die "file not found" unless -f $file && -r _;

    $r->content_type($type);
    open my $fh, "<$file" or die "couldn't open file: $!";
    binmode($fh);
    {
        local $/ = \16384;
        $m->out($_) while (<$fh>);
        $m->flush_buffer;
    }
    close $fh;
    $m->abort;
}
elsif ( $file =~ /\.js/ ) {
    #&RT::Interface::Web::StaticFileHeaders();
    $r->content_type('application/x-javascript');
    $m->call_next();
    $m->abort;
}
elsif ( $file =~ /\.css/ ) {
    #RT::Interface::Web::StaticFileHeaders();
    $r->content_type('text/css');
    $m->call_next();
    $m->abort;
}
else {
    $m->call_next;
}

</%init>
