From: Steinar H. Gunderson Date: Mon, 25 Dec 2006 16:41:04 +0000 (+0100) Subject: Make static files be cacheable, and send proper content-length/last-modified X-Git-Url: https://git.sesse.net/?p=pr0n;a=commitdiff_plain;h=451bbfdf39a274b62761afc13cb6dced98a7ca5a;ds=sidebyside Make static files be cacheable, and send proper content-length/last-modified headers for them. --- diff --git a/perl/Sesse/pr0n/pr0n.pm b/perl/Sesse/pr0n/pr0n.pm index 28df871..1395168 100644 --- a/perl/Sesse/pr0n/pr0n.pm +++ b/perl/Sesse/pr0n/pr0n.pm @@ -29,7 +29,18 @@ sub handler { $uri eq '/close.png' || $uri =~ m#^/usage/([a-zA-Z0-9_.]+)$#) { $uri =~ s#^/##; + my $fname = Sesse::pr0n::Common::get_base($r) . 'files/' . $uri; + my (undef, undef, undef, undef, undef, undef, undef, $size, undef, $mtime) = stat($fname) + or error($r, "stat of $fname: $!"); + $r->content_type(Sesse::pr0n::Common::get_mimetype_from_filename($uri)); + $r->set_content_length($size); + $r->set_last_modified($mtime); + + if((my $rc = $r->meets_conditions) != OK) { + return $rc; + } + $r->sendfile(Sesse::pr0n::Common::get_base($r) . 'files/' . $uri); return Apache2::Const::OK; } elsif ($uri eq '/newevent.html') {