<%INIT>
&RT::Interface::Web::StaticFileHeaders();
use File::Basename;
my $arg = $m->dhandler_arg;
my $file = dirname($m->current_comp->source_file) . '/source/'. $arg;

my $type = "application/octet-stream";
if ($file =~ /\.(gif|png|jpe?g)$/i) {
    $type = "image/$1";
    $type =~ s/jpg/jpeg/gi;
}

die "File $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;
</%INIT>
