1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
|
# Test extra HTTP::Response methods. Basic operation is tested in the
# message.t test suite.
print "1..7\n";
use HTTP::Date;
use HTTP::Request;
use HTTP::Response;
my $time = time;
$req = HTTP::Request->new(GET => 'http://www.sn.no');
$req->date($time - 30);
$r = new HTTP::Response 200, "OK";
$r->client_date($time - 20);
$r->date($time - 25);
$r->last_modified($time - 5000000);
$r->request($req);
print $r->as_string;
$current_age = $r->current_age;
if ($current_age < 35 || $current_age > 40) {
print "not ";
}
print "ok 1\n";
$freshness_lifetime = $r->freshness_lifetime;
if ($freshness_lifetime < 12 * 3600) {
print "not ";
}
print "ok 2\n";
$is_fresh = $r->is_fresh;
print "not " unless $is_fresh;
print "ok 3\n";
print "current_age = $current_age\n";
print "freshness_lifetime = $freshness_lifetime\n";
print "response is ";
print "not " unless $is_fresh;
print "fresh\n";
print "it will be fresh is ";
print $freshness_lifetime - $current_age;
print " more seconds\n";
# OK, now we add an Expires header
$r->expires($time);
print $r->as_string;
$freshness_lifetime = $r->freshness_lifetime;
print "freshness_lifetime = $freshness_lifetime\n";
print "not " unless $freshness_lifetime == 25;
print "ok 4\n";
$r->remove_header('expires');
# Now we try the 'Age' header and the Cache-Contol:
$r->header('Age', 300);
$r->push_header('Cache-Control', 'junk');
$r->push_header(Cache_Control => 'max-age = 10');
print $r->as_string;
$current_age = $r->current_age;
$freshness_lifetime = $r->freshness_lifetime;
print "current_age = $current_age\n";
print "freshness_lifetime = $freshness_lifetime\n";
print "not " if $current_age < 300;
print "ok 5\n";
print "not " if $freshness_lifetime != 10;
print "ok 6\n";
print "not " unless $r->fresh_until; # should return something
print "ok 7\n";
|