in t/modules/expires.t [192:257]
sub expires_test {
my $expires_active = shift;
my $head_str = shift;
my %headers = ();
foreach my $header (split /\n/, $head_str) {
if ($header =~ /^([\-\w]+): (.*)$/) {
print "# debug: [$1] [$2]\n";
$headers{$names{$1}} = $2 if exists $names{$1};
}
}
## expires header should not exist if ExpiresActive is Off ##
return !$headers{expires} unless ($expires_active);
for my $h (grep !/^type$/, values %names) {
print "# debug: $h @{[$headers{$h}||'']}\n";
if ($headers{$h}) {
$headers{$h} = convert_to_time($headers{$h}) || 0;
} else {
$headers{$h} = 0;
}
print "# debug: $h $headers{$h}\n";
}
my $exp_conf = '';
if ( exists $exp{ $headers{type} } and $exp{ $headers{type} }) {
$exp_conf = $exp{ $headers{type} };
} else {
$exp_conf = $exp{'default'};
}
## if expect is set to '0', Expire header should not exist. ##
if ($exp_conf eq '0') {
return !$headers{expires};
}
my $expected = '';
my $exp_type = '';
if ($exp_conf =~ /^([A|M])(\d+)$/) {
$exp_type = $1;
$expected = $2;
## With modification date as base expire times can be in the past
## Correct behaviour for the server in this case is to set expires
## time equal to access time.
if (($exp_type eq 'M')
&& ($headers{access} > $headers{modified} + $expected)) {
$expected = $headers{access} - $headers{modified};
}
} else {
print STDERR "\n\ndoom: $exp_conf\n\n";
return 0;
}
my $actual = 0;
if ($exp_type eq 'M') {
$actual = $headers{expires} - $headers{modified};
} elsif ($exp_type eq 'A') {
$actual = $headers{expires} - $headers{access};
}
print "# debug: expected: $expected\n";
print "# debug: actual : $actual\n";
return ($actual == $expected);
}