]> git.sesse.net Git - pr0n/commitdiff
Make static files be cacheable, and send proper content-length/last-modified
authorSteinar H. Gunderson <sesse@debian.org>
Mon, 25 Dec 2006 16:41:04 +0000 (17:41 +0100)
committerSteinar H. Gunderson <sesse@debian.org>
Mon, 25 Dec 2006 16:41:04 +0000 (17:41 +0100)
headers for them.

perl/Sesse/pr0n/pr0n.pm

index 28df8719a04ecebabfbe8283ae7e89de6622e7e9..1395168f224a7f8e209305e5c334c315085fffe2 100644 (file)
@@ -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') {