| 1 |
# This is the old message.t test. It is not maintained any more, |
| 2 |
# but kept around in case it happens to catch any mistakes. Please |
| 3 |
# add new tests to message.t instead. |
| 4 |
|
| 5 |
use strict; |
| 6 |
use warnings; |
| 7 |
|
| 8 |
use Test::More; |
| 9 |
|
| 10 |
plan tests => 20; |
| 11 |
|
| 12 |
require HTTP::Request; |
| 13 |
require HTTP::Response; |
| 14 |
|
| 15 |
require Time::Local if $^O eq "MacOS"; |
| 16 |
my $offset = ($^O eq "MacOS") ? Time::Local::timegm(0,0,0,1,0,1970) : 0; |
| 17 |
|
| 18 |
my $req = HTTP::Request->new(GET => "http://www.sn.no/"); |
| 19 |
$req->header( |
| 20 |
"if-modified-since" => "Thu, 03 Feb 1994 00:00:00 GMT", |
| 21 |
"mime-version" => "1.0"); |
| 22 |
|
| 23 |
ok($req->as_string =~ /^GET/m); |
| 24 |
is($req->header("MIME-Version"), "1.0"); |
| 25 |
is($req->if_modified_since, ((760233600 + $offset) || 0)); |
| 26 |
|
| 27 |
$req->content("gisle"); |
| 28 |
$req->add_content(" aas"); |
| 29 |
$req->add_content(\ " old interface is depreciated"); |
| 30 |
${$req->content_ref} =~ s/\s+is\s+depreciated//; |
| 31 |
|
| 32 |
is($req->content, "gisle aas old interface"); |
| 33 |
|
| 34 |
my $time = time; |
| 35 |
$req->date($time); |
| 36 |
my $timestr = gmtime($time); |
| 37 |
my($month) = ($timestr =~ /^\S+\s+(\S+)/); # extract month; |
| 38 |
#print "These should represent the same time:\n\t", $req->header('Date'), "\n\t$timestr\n"; |
| 39 |
like($req->header('Date'), qr/\Q$month/); |
| 40 |
|
| 41 |
$req->authorization_basic("gisle", "passwd"); |
| 42 |
is($req->header("Authorization"), "Basic Z2lzbGU6cGFzc3dk"); |
| 43 |
|
| 44 |
my($user, $pass) = $req->authorization_basic; |
| 45 |
is($user, "gisle"); |
| 46 |
is($pass, "passwd"); |
| 47 |
|
| 48 |
# Check the response |
| 49 |
my $res = HTTP::Response->new(200, "This message"); |
| 50 |
ok($res->is_success); |
| 51 |
|
| 52 |
my $html = $res->error_as_HTML; |
| 53 |
ok($html =~ /<head>/i && $html =~ /This message/); |
| 54 |
|
| 55 |
$res->content_type("text/html;version=3.0"); |
| 56 |
$res->content("<html>...</html>\n"); |
| 57 |
|
| 58 |
my $res2 = $res->clone; |
| 59 |
is($res2->code, 200); |
| 60 |
is($res2->header("cOntent-TYPE"), "text/html;version=3.0"); |
| 61 |
like($res2->content, qr/>\.\.\.</); |
| 62 |
|
| 63 |
# Check the base method: |
| 64 |
$res = HTTP::Response->new(200, "This message"); |
| 65 |
is($res->base, undef); |
| 66 |
$res->request($req); |
| 67 |
$res->content_type("image/gif"); |
| 68 |
|
| 69 |
is($res->base, "http://www.sn.no/"); |
| 70 |
$res->header('Base', 'http://www.sn.no/xxx/'); |
| 71 |
is($res->base, "http://www.sn.no/xxx/"); |
| 72 |
|
| 73 |
# Check the AUTLOAD delegate method with regular expressions |
| 74 |
"This string contains text/html" =~ /(\w+\/\w+)/; |
| 75 |
$res->content_type($1); |
| 76 |
is($res->content_type, "text/html"); |
| 77 |
|
| 78 |
# Check what happens when passed a new URI object |
| 79 |
require URI; |
| 80 |
$req = HTTP::Request->new(GET => URI->new("http://localhost")); |
| 81 |
is($req->uri, "http://localhost"); |
| 82 |
|
| 83 |
$req = HTTP::Request->new(GET => "http://www.example.com", |
| 84 |
[ Foo => 1, bar => 2 ], "FooBar\n"); |
| 85 |
is($req->as_string, <<EOT); |
| 86 |
GET http://www.example.com |
| 87 |
Bar: 2 |
| 88 |
Foo: 1 |
| 89 |
|
| 90 |
FooBar |
| 91 |
EOT |
| 92 |
|
| 93 |
$req->clear; |
| 94 |
is($req->as_string, <<EOT); |
| 95 |
GET http://www.example.com |
| 96 |
|
| 97 |
EOT |