HTTP-Daemon
view release on metacpan or search on metacpan
$req = HTTP::Request->new(GET => $daemon->url("/file", { file => $filename }));
$res = $ua->request($req);
#print $res->as_string;
ok($res->is_success);
is($res->content_type, 'text/html');
is($res->content_length, 147);
is($res->title, "En pr\xF8ve");
like($res->content, qr/\xE5 v\xE6re/);
unlink $filename;
# A second try on the same file, should fail because we unlink it
$res = $ua->request($req);
#print $res->as_string;
ok($res->is_error);
is($res->code, 404); # not found
}
# Then try to list current directory
$req = HTTP::Request->new(GET => $daemon->url("/file?file=."));
$res = $ua->request($req);
#print $res->as_string;
is($res->code, 501); # NYI
#----------------------------------------------------------------
note "Check redirect...\n";
$req = HTTP::Request->new(GET => $daemon->url("/redirect/foo"));
$res = $ua->request($req);
ok($res->is_success);
like($res->content, qr|/echo/redirect|);
ok($res->previous->is_redirect);
is($res->previous->code, 301);
#----------------------------------------------------------------
note "Check basic authorization...\n";
$req = HTTP::Request->new(GET => $daemon->url("/basic"));
my $auth = MIME::Base64::encode("ok 12:xyzzy");
$req->header(Authorization => 'Basic ' . $auth);
$res = $ua->request($req);
ok($res->is_success);
$req->header('Authorization' => undef);
$res = $ua->request($req);
is($res->code, 401);
$auth = MIME::Base64::encode("user:passwd");
$req->header(Authorization => 'Basic ' . $auth);
# Then illegal credentials
$res = $ua->request($req);
is($res->code, 401);
#----------------------------------------------------------------
note "Check proxy...\n";
$ua->proxy(ftp => $base);
$req = HTTP::Request->new(GET => "ftp://ftp.perl.com/proxy");
$res = $ua->request($req);
#print $res->as_string;
ok($res->is_success);
$ua->proxy(ftp => undef);
#----------------------------------------------------------------
note "Check POSTing...\n";
$req = HTTP::Request->new(POST => $daemon->url("/echo/foo"));
$req->content_type("application/x-www-form-urlencoded");
$req->content("foo=bar&bar=test");
$res = $ua->request($req);
#print $res->as_string;
$_ = $res->content;
ok($res->is_success);
like($_, qr/^Content-Length:\s*16$/mi);
like($_, qr/^Content-Type:\s*application\/x-www-form-urlencoded$/mi);
like($_, qr/^foo=bar&bar=test$/m);
$req = HTTP::Request->new(POST => $daemon->url("/echo/foo"));
$req->content_type("multipart/form-data");
$req->add_part(HTTP::Message->new(["Content-Type" => "text/plain"], "Hi\n"));
$req->add_part(HTTP::Message->new(["Content-Type" => "text/plain"], "there\n"));
$res = $ua->request($req);
#print $res->as_string;
ok($res->is_success);
like($res->content, qr/^Content-Type: multipart\/form-data; boundary=/m);
#----------------------------------------------------------------
note "Terminating server...\n";
$req = HTTP::Request->new(GET => $daemon->url("/quit"));
$res = $ua->request($req);
is($res->code, 503);
like($res->content, qr/Bye, bye/);
( run in 0.916 second using v1.01-cache-2.11-cpan-39bf76dae61 )