Catalyst-Plugin-Static
view release on metacpan or search on metacpan
lib/Catalyst/Plugin/Static.pm view on Meta::CPAN
Serve a specified static file.
=cut
sub serve_static_file {
my $c = shift;
my $path = catdir(no_upwards(splitdir( shift )));
if ( -f $path ) {
my $stat = stat($path);
if ( $c->req->headers->header('If-Modified-Since') ) {
if ( $c->req->headers->if_modified_since == $stat->mtime ) {
$c->res->status(304); # Not Modified
$c->res->headers->remove_content_headers;
return 1;
}
}
t/02static.t view on Meta::CPAN
use Test::More tests => 10;
use lib 't/lib';
use Catalyst::Test 'TestApp';
use File::stat;
use File::Slurp;
use HTTP::Date;
use HTTP::Request::Common;
my $stat = stat($0);
{
ok( my $response = request('/02static.t'), 'Request' );
is( $response->code, 200, 'OK status code' );
is( $response->content_length, $stat->size, 'Content length' );
is( $response->last_modified, $stat->mtime, 'Modified date' );
is( $response->content, read_file($0), 'Content' );
}
{
( run in 0.569 second using v1.01-cache-2.11-cpan-49f99fa48dc )