From 451bbfdf39a274b62761afc13cb6dced98a7ca5a Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Mon, 25 Dec 2006 17:41:04 +0100 Subject: [PATCH] Make static files be cacheable, and send proper content-length/last-modified headers for them. --- perl/Sesse/pr0n/pr0n.pm | 11 +++++++++++ 1 file changed, 11 insertions(+) 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') { -- 2.39.2