2 # Test extra HTTP::Response methods. Basic operation is tested in the
3 # message.t test suite.
15 $req = HTTP::Request->new(GET => 'http://www.sn.no');
16 $req->date($time - 30);
18 $r = new HTTP::Response 200, "OK";
19 $r->client_date($time - 20);
21 $r->last_modified($time - 5000000);
26 $current_age = $r->current_age;
28 if ($current_age < 35 || $current_age > 40) {
33 $freshness_lifetime = $r->freshness_lifetime;
34 if ($freshness_lifetime < 12 * 3600) {
39 $is_fresh = $r->is_fresh;
41 print "not " unless $is_fresh;
44 print "current_age = $current_age\n";
45 print "freshness_lifetime = $freshness_lifetime\n";
47 print "not " unless $is_fresh;
51 print "it will be fresh is ";
52 print $freshness_lifetime - $current_age;
53 print " more seconds\n";
55 # OK, now we add an Expires header
59 $freshness_lifetime = $r->freshness_lifetime;
60 print "freshness_lifetime = $freshness_lifetime\n";
61 print "not " unless $freshness_lifetime == 25;
63 $r->remove_header('expires');
65 # Now we try the 'Age' header and the Cache-Contol:
67 $r->header('Age', 300);
68 $r->push_header('Cache-Control', 'junk');
69 $r->push_header(Cache_Control => 'max-age = 10');
73 $current_age = $r->current_age;
74 $freshness_lifetime = $r->freshness_lifetime;
76 print "current_age = $current_age\n";
77 print "freshness_lifetime = $freshness_lifetime\n";
79 print "not " if $current_age < 300;
82 print "not " if $freshness_lifetime != 10;
85 print "not " unless $r->fresh_until; # should return something
88 my $r2 = HTTP::Response->parse($r->as_string);
89 my @h = $r2->header('Cache-Control');
90 print "not " unless scalar @h == 2;