3 # This is the old message.t test. It is not maintained any more,
4 # but kept around in case it happens to catch any mistakes. Please
5 # add new tests to message.t instead.
12 require HTTP::Request;
13 require HTTP::Response;
15 require Time::Local if $^O eq "MacOS";
16 my $offset = ($^O eq "MacOS") ? Time::Local::timegm(0,0,0,1,0,70) : 0;
18 my $req = HTTP::Request->new(GET => "http://www.sn.no/");
20 "if-modified-since" => "Thu, 03 Feb 1994 00:00:00 GMT",
21 "mime-version" => "1.0");
23 ok($req->as_string =~ /^GET/m);
24 ok($req->header("MIME-Version"), "1.0");
25 ok($req->if_modified_since, ((760233600 + $offset) || 0));
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//;
32 ok($req->content, "gisle aas old interface");
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 ok($req->header('Date') =~ /\Q$month/);
41 $req->authorization_basic("gisle", "passwd");
42 ok($req->header("Authorization"), "Basic Z2lzbGU6cGFzc3dk");
44 my($user, $pass) = $req->authorization_basic;
49 my $res = HTTP::Response->new(200, "This message");
52 my $html = $res->error_as_HTML;
53 ok($html =~ /<head>/i && $html =~ /This message/);
55 $res->content_type("text/html;version=3.0");
56 $res->content("<html>...</html>\n");
58 my $res2 = $res->clone;
60 ok($res2->header("cOntent-TYPE"), "text/html;version=3.0");
61 ok($res2->content =~ />\.\.\.</);
63 # Check the base method:
64 $res = HTTP::Response->new(200, "This message");
65 ok($res->base, undef);
67 $res->content_type("image/gif");
69 ok($res->base, "http://www.sn.no/");
70 $res->header('Base', 'http://www.sn.no/xxx/');
71 ok($res->base, "http://www.sn.no/xxx/");
73 # Check the AUTLOAD delegate method with regular expressions
74 "This string contains text/html" =~ /(\w+\/\w+)/;
75 $res->content_type($1);
76 ok($res->content_type, "text/html");
78 # Check what happens when passed a new URI object
80 $req = HTTP::Request->new(GET => URI->new("http://localhost"));
81 ok($req->uri, "http://localhost");
83 $req = HTTP::Request->new(GET => "http://www.example.com",
84 [ Foo => 1, bar => 2 ], "FooBar\n");
85 ok($req->as_string, <<EOT);
86 GET http://www.example.com
94 ok($req->as_string, <<EOT);
95 GET http://www.example.com