if($cb) {
while ($content = &$collector, length $$content) {
eval {
&$cb($$content, $response, $self);
};
if ($@) {
chomp($@);
$response->header('X-Died' => $@);
last;
}
}
}
####
#! /usr/bin/perl -w
# bloat.cgi
use strict;
print <bloat.cgi -- a humungous web page
HEAD
print qq{$_
\n} for( 1 .. 10000 );
print '';
__END__
##
##
#! /usr/bin/perl -w
use strict;
use LWP::UserAgent;
use HTTP::Request;
use HTML::Parser;
my $chunk = 0;
my $p = HTML::Parser->new(
start_h => [ \&begin, 'tagname,attr' ],
default_h => [ \&content, 'text' ],
end_h => [ \&end, 'tagname' ],
);
my $ua = LWP::UserAgent->new;
my $req = HTTP::Request->new(GET => 'http://localhost/cgi-bin/bloat.cgi' );
my $res = $ua->request($req, \&cb);
$p->eof;
sub cb {
my $received = shift;
++$chunk;
$p->parse( $received );
}
sub begin {
my $element = shift;
my $r = shift;
print "received <$element";
print qq{ $_="$r->{$_}"} foreach keys %$r;
print "> at chunk $chunk\n";
}
sub content {
my $content = shift;
print "received [$content] at chunk $chunk\n";
###########################
die if $content eq '123'; #
###########################
}
sub end {
my $element = shift;
print "received $element> at chunk $chunk\n";
}
__END__
##
##
127.0.0.1 - - [15/Oct/2001:10:40:14 +0200] "GET /cgi-bin/bloat.cgi HTTP/1.0" 200 527879 "-" "lwp-request/1.39"
127.0.0.1 - - [15/Oct/2001:10:40:18 +0200] "GET /cgi-bin/bloat.cgi HTTP/1.0" 200 116807 "-" "libwww-perl/5.53"