HTTP-Daemon-Threaded
view release on metacpan or search on metacpan
use LWPBulkFetch;
use strict;
use warnings;
#
# forks a child to run system('perl somescript.pl'),
# which this process monitors
#
my $child1;
my $sep = ($^O eq 'MSWin32') ? '\\' : '/';
unless ($ARGV[0]) {
$child1 = fork();
die "Can't fork HTTP Client child: $!" unless defined $child1;
unless ($child1) {
my $cmd = 'perl -w t' . $sep . 'cgidtest.pl -p 11876 -c 5 -d ./t -l 1 -s';
system($cmd);
exit 1;
}
#
# wait a while for things to get rolling
#
sleep 5;
}
my $index = '<html><body>Some really simple HTML.</body></html>';
my ($ct, $cl, $mtime, $exp, $server);
#
# now run each LWP request and see what we get back
#
# 1. simple HEAD
#
my $indexlen = length($index); # change this!
($ct, $cl, $mtime, $exp, $server) = head('http://localhost:11876/index.html');
ok((defined($ct) && ($ct eq 'text/html') &&
defined($cl) && ($cl == $indexlen)), 'simple HEAD');
#
# 2. simple GET
#
my $page = get 'http://localhost:11876';
ok((defined($page) && ($page eq $index)), 'simple GET');
#
# 3. document HEAD
#
my $jspage = '/*
this would normally be a nice piece of javascript
*/
';
($ct, $cl, $mtime, $exp, $server) = head('http://localhost:11876/scripty.js');
ok((defined($ct) && ($ct eq 'text/javascript') &&
defined($cl) && (($cl == crlen($jspage)) || ($cl == length($jspage)))),
'document HEAD');
#
# 4. CGI HEAD
#
my $postpg = <<'EOPAGE';
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-US" xml:lang="en-US">
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
that is other<br>
this is some<br>
when is right this minute<br>
where is up<br>
</body>
</html>
EOPAGE
($ct, $cl, $mtime, $exp, $server) = head('http://localhost:11876/posted?this=some&that=other&where=up&when=right%20this%20minute');
#print STDERR "head returns ", join(",", $ct, $mtime, $exp, $server), "\n";
ok((defined($ct) && ($ct eq 'text/html; charset=UTF-8')), 'document HEAD');
# 5. document GET
#
$page = get 'http://localhost:11876/scripty.js';
ok((defined($page) && (!crcmp($page, $jspage))), 'document GET');
#
# 6. CGI GET
#
$page = get 'http://localhost:11876/posted?this=some&that=other&where=up&when=right%20this%20minute';
ok((defined($page) && (!crcmp($page, $postpg))), 'CGI GET');
#
# 7. multidoc GET
#
my %multidoc = (
'http://localhost:11876/frames.html',
"<html>
<head><title>Test Content Handler</title>
</head>
<frameset rows='55%,45%'>
<frameset cols='80%,20%'>
<frame id='sources' src='sourcepane.html' scrolling=no frameborder=1>
<frame id='srctree' src='sourcetree.html' scrolling=yes frameborder=1>
</frameset>
<frame name='stackpane' src='stackpane.html' scrolling=no frameborder=0>
</frameset>
</html>
",
'http://localhost:11876/stackpane.html',
'<html>
<body>
Some other stuff goes here...
</body>
</html>
',
'http://localhost:11876/sourcepane.html',
'<html>
( run in 2.160 seconds using v1.01-cache-2.11-cpan-119454b85a5 )