Skip to content
Snippets Groups Projects
Commit 43f48659 authored by Kevin Atkinson's avatar Kevin Atkinson
Browse files

Add support for If-Modified-Since.

Also now depends on HTTP::Date found in the p5-libwww package.
parent a76eec15
No related branches found
No related tags found
No related merge requests found
......@@ -7,10 +7,11 @@
use strict;
use warnings;
use POSIX qw(setuid setgid strftime);
use POSIX qw(setuid setgid);
use Cwd qw(realpath);
use CGI;
use CGI::Cookie;
use HTTP::Date;
#use Data::Dumper;
......@@ -28,12 +29,6 @@ sub error($) {
exit 1;
}
sub http_date_str ($)
{
my ($time) = @_;
strftime("%a, %d %b %Y %T GMT", gmtime($time));
}
my $SCRIPT_URL = $ENV{SCRIPT_URL};
# Parse URL
......@@ -177,11 +172,18 @@ open F, "$path" or error "Can't read file: $path";
my ($dev,$ino,$mode,$nlink,undef,undef,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks) = stat F;
print "Content-Type: $mime_type\n" if defined $mime_type;
print "Content-Length: ", $size, "\n";
print "Last-Modified: ", http_date_str($mtime), "\n";
print "\n";
print <F>;
my $if_mod_since = 0;
$if_mod_since = str2time($ENV{HTTP_IF_MODIFIED_SINCE})
if defined $ENV{HTTP_IF_MODIFIED_SINCE};
if ($if_mod_since > 0 && $if_mod_since <= $mtime) {
print "Status: 304 Not Modified\n\n";
} else {
print "Content-Type: $mime_type\n" if defined $mime_type;
print "Content-Length: ", $size, "\n";
print "Last-Modified: ", time2str($mtime), "\n";
print "\n";
print <F>;
}
exit 0;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment