|
Packit |
a09cf7 |
# This is the old message.t test. It is not maintained any more,
|
|
Packit |
a09cf7 |
# but kept around in case it happens to catch any mistakes. Please
|
|
Packit |
a09cf7 |
# add new tests to message.t instead.
|
|
Packit |
a09cf7 |
|
|
Packit |
a09cf7 |
use strict;
|
|
Packit |
a09cf7 |
use warnings;
|
|
Packit |
a09cf7 |
|
|
Packit |
a09cf7 |
use Test::More;
|
|
Packit |
a09cf7 |
|
|
Packit |
a09cf7 |
plan tests => 20;
|
|
Packit |
a09cf7 |
|
|
Packit |
a09cf7 |
require HTTP::Request;
|
|
Packit |
a09cf7 |
require HTTP::Response;
|
|
Packit |
a09cf7 |
|
|
Packit |
a09cf7 |
require Time::Local if $^O eq "MacOS";
|
|
Packit |
a09cf7 |
my $offset = ($^O eq "MacOS") ? Time::Local::timegm(0,0,0,1,0,1970) : 0;
|
|
Packit |
a09cf7 |
|
|
Packit |
a09cf7 |
my $req = HTTP::Request->new(GET => "http://www.sn.no/");
|
|
Packit |
a09cf7 |
$req->header(
|
|
Packit |
a09cf7 |
"if-modified-since" => "Thu, 03 Feb 1994 00:00:00 GMT",
|
|
Packit |
a09cf7 |
"mime-version" => "1.0");
|
|
Packit |
a09cf7 |
|
|
Packit |
a09cf7 |
ok($req->as_string =~ /^GET/m);
|
|
Packit |
a09cf7 |
is($req->header("MIME-Version"), "1.0");
|
|
Packit |
a09cf7 |
is($req->if_modified_since, ((760233600 + $offset) || 0));
|
|
Packit |
a09cf7 |
|
|
Packit |
a09cf7 |
$req->content("gisle");
|
|
Packit |
a09cf7 |
$req->add_content(" aas");
|
|
Packit |
a09cf7 |
$req->add_content(\ " old interface is depreciated");
|
|
Packit |
a09cf7 |
${$req->content_ref} =~ s/\s+is\s+depreciated//;
|
|
Packit |
a09cf7 |
|
|
Packit |
a09cf7 |
is($req->content, "gisle aas old interface");
|
|
Packit |
a09cf7 |
|
|
Packit |
a09cf7 |
my $time = time;
|
|
Packit |
a09cf7 |
$req->date($time);
|
|
Packit |
a09cf7 |
my $timestr = gmtime($time);
|
|
Packit |
a09cf7 |
my($month) = ($timestr =~ /^\S+\s+(\S+)/); # extract month;
|
|
Packit |
a09cf7 |
#print "These should represent the same time:\n\t", $req->header('Date'), "\n\t$timestr\n";
|
|
Packit |
a09cf7 |
like($req->header('Date'), qr/\Q$month/);
|
|
Packit |
a09cf7 |
|
|
Packit |
a09cf7 |
$req->authorization_basic("gisle", "passwd");
|
|
Packit |
a09cf7 |
is($req->header("Authorization"), "Basic Z2lzbGU6cGFzc3dk");
|
|
Packit |
a09cf7 |
|
|
Packit |
a09cf7 |
my($user, $pass) = $req->authorization_basic;
|
|
Packit |
a09cf7 |
is($user, "gisle");
|
|
Packit |
a09cf7 |
is($pass, "passwd");
|
|
Packit |
a09cf7 |
|
|
Packit |
a09cf7 |
# Check the response
|
|
Packit |
a09cf7 |
my $res = HTTP::Response->new(200, "This message");
|
|
Packit |
a09cf7 |
ok($res->is_success);
|
|
Packit |
a09cf7 |
|
|
Packit |
a09cf7 |
my $html = $res->error_as_HTML;
|
|
Packit |
a09cf7 |
ok($html =~ /<head>/i && $html =~ /This message/);
|
|
Packit |
a09cf7 |
|
|
Packit |
a09cf7 |
$res->content_type("text/html;version=3.0");
|
|
Packit |
a09cf7 |
$res->content("<html>...</html>\n");
|
|
Packit |
a09cf7 |
|
|
Packit |
a09cf7 |
my $res2 = $res->clone;
|
|
Packit |
a09cf7 |
is($res2->code, 200);
|
|
Packit |
a09cf7 |
is($res2->header("cOntent-TYPE"), "text/html;version=3.0");
|
|
Packit |
a09cf7 |
like($res2->content, qr/>\.\.\.</);
|
|
Packit |
a09cf7 |
|
|
Packit |
a09cf7 |
# Check the base method:
|
|
Packit |
a09cf7 |
$res = HTTP::Response->new(200, "This message");
|
|
Packit |
a09cf7 |
is($res->base, undef);
|
|
Packit |
a09cf7 |
$res->request($req);
|
|
Packit |
a09cf7 |
$res->content_type("image/gif");
|
|
Packit |
a09cf7 |
|
|
Packit |
a09cf7 |
is($res->base, "http://www.sn.no/");
|
|
Packit |
a09cf7 |
$res->header('Base', 'http://www.sn.no/xxx/');
|
|
Packit |
a09cf7 |
is($res->base, "http://www.sn.no/xxx/");
|
|
Packit |
a09cf7 |
|
|
Packit |
a09cf7 |
# Check the AUTLOAD delegate method with regular expressions
|
|
Packit |
a09cf7 |
"This string contains text/html" =~ /(\w+\/\w+)/;
|
|
Packit |
a09cf7 |
$res->content_type($1);
|
|
Packit |
a09cf7 |
is($res->content_type, "text/html");
|
|
Packit |
a09cf7 |
|
|
Packit |
a09cf7 |
# Check what happens when passed a new URI object
|
|
Packit |
a09cf7 |
require URI;
|
|
Packit |
a09cf7 |
$req = HTTP::Request->new(GET => URI->new("http://localhost"));
|
|
Packit |
a09cf7 |
is($req->uri, "http://localhost");
|
|
Packit |
a09cf7 |
|
|
Packit |
a09cf7 |
$req = HTTP::Request->new(GET => "http://www.example.com",
|
|
Packit |
a09cf7 |
[ Foo => 1, bar => 2 ], "FooBar\n");
|
|
Packit |
a09cf7 |
is($req->as_string, <
|
|
Packit |
a09cf7 |
GET http://www.example.com
|
|
Packit |
a09cf7 |
Bar: 2
|
|
Packit |
a09cf7 |
Foo: 1
|
|
Packit |
a09cf7 |
|
|
Packit |
a09cf7 |
FooBar
|
|
Packit |
a09cf7 |
EOT
|
|
Packit |
a09cf7 |
|
|
Packit |
a09cf7 |
$req->clear;
|
|
Packit |
a09cf7 |
is($req->as_string, <
|
|
Packit |
a09cf7 |
GET http://www.example.com
|
|
Packit |
a09cf7 |
|
|
Packit |
a09cf7 |
EOT
|