HTTP-Daemon-Threaded

 view release on metacpan or  search on metacpan

t/04cgistress.t  view on Meta::CPAN

#
#	shutdown the server
#
if ($forkhttpd) {
	get "http://localhost:$port/stop";

	kill($child1);

	waitpid($child1, 0);
}

sub run {
	my ($port, $cycles) = @_;

	my $url = "http://localhost:$port/";
	my $index = '<html><body>Some really simple HTML.</body></html>';
	my ($ct, $cl, $mtime, $exp, $server);
	my $indexlen = length($index);	# change this!
#
#	now run each LWP request and see what we get back
#
#	1. simple HEAD
#
	foreach (1..$cycles) {
	print STDERR "Simple HEAD\n"
		unless $quiet;

	($ct, $cl, $mtime, $exp, $server) = head($url . 'index.html');
	return 0
		unless (defined($ct) && ($ct eq 'text/html'));
#
#	2. simple GET
#
	print STDERR "Simple GET\n"
		unless $quiet;

	my $page = get $url;
	return 0 unless (defined($page) && ($page eq $index));
#
#	3. document HEAD
#
	print STDERR "Document HEAD\n"
		unless $quiet;
	my $jspage =
'/*
 this would normally be a nice piece of javascript
*/
';

	($ct, $cl, $mtime, $exp, $server) = head($url . 'scripty.js');
	return 0 unless	(defined($ct) && ($ct eq 'text/javascript') &&
		defined($cl) && (($cl == crlen($jspage)) || ($cl == length($jspage))));
#
#	4. CGI HEAD
#
	print STDERR "CGI HEAD\n"
		unless $quiet;

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($url . 'posted?this=some&that=other&where=up&when=right%20this%20minute');
	return 0 unless (defined($ct) && ($ct eq 'text/html; charset=UTF-8'));
#
#	5. document GET
#
	print STDERR "Document GET\n"
		unless $quiet;
	$page = get $url . 'scripty.js';
	return 0 unless (defined($page) && (!crcmp($page, $jspage)));
#
#	6. CGI GET
#
	print STDERR "CGI GET\n"
		unless $quiet;
	$page = get $url . 'posted?this=some&that=other&where=up&when=right%20this%20minute';
	return 0 unless (defined($page) && (!crcmp($page, $postpg)));
#
#	7. multidoc GET
#
	print STDERR "Multidoc GET\n"
		unless $quiet;

my %multidoc = (
$url . '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>
",

$url . 'stackpane.html',
'<html>
<body>



( run in 0.761 second using v1.01-cache-2.11-cpan-acf6aa7dc9e )