App-FakeCDN

 view release on metacpan or  search on metacpan

lib/App/FakeCDN.pm  view on Meta::CPAN

        my $path  = $env->{PATH_INFO} // '';
        my $query = $env->{QUERY_STRING} // '';

        if ($path =~ /\0/ || $query =~ /\0/) {
            return $self->res_400;
        }
        $path =~ s!^/!!;

        my ($data, $content_type) = $self->get_content($path, $query);

        return $self->res_404 unless $data;

        return [ 200, [
            'Content-Type'   => $content_type,
            'Content-Length' => length($data),
        ], [ $data ] ];
    };
}

sub res_400 {
    [400, ['Content-Type' => 'text/plain', 'Content-Length' => 11], ['Bad Request']];
}

sub res_404 {
    [404, ['Content-Type' => 'text/plain', 'Content-Length' => 9], ['not found']];
}

sub get_content {
    my ($self, $path, $query) = @_;

    my $mime_type = Plack::MIME->mime_type($path) // 'application/octet-stream';
    my $is_binary = is_binary($mime_type);

    unless ($is_binary) {
        my $encoding = $self->encoding || 'utf-8';



( run in 0.746 second using v1.01-cache-2.11-cpan-39bf76dae61 )