Test-HTTP-AnyEvent-Server
view release on metacpan or search on metacpan
lib/Test/HTTP/AnyEvent/Server.pm view on Meta::CPAN
# parent
my $pid = $_;
close $wh;
my $buf;
my $len = sysread $rh, $buf, 65536;
AE::log fatal =>
"couldn't sysread() from pipe: $!"
if not defined $len or not $len;
my ($address, $port) = split m{\t}x, $buf;
$self->set_address($address);
$self->set_port($port);
$self->set_forked_pid($pid);
AE::log info =>
"forked as $pid and bound to " . $self->uri;
}
}
}
return;
lib/Test/HTTP/AnyEvent/Server.pm view on Meta::CPAN
$self->_start($h);
} => $cb
);
}
sub _start {
my ($self, $my_handle) = @_;
return $my_handle->push_read(regex => qr{(\015?\012){2}}x, sub {
my ($h, $data) = @_;
my ($req, $hdr) = split m{\015?\012}x, $data, 2;
$req =~ s/\s+$//sx;
AE::log debug => "request: [$req]\n";
if ($hdr =~ m{\bContent-length:\s*(\d+)\b}isx) {
AE::log debug => "expecting content\n";
$h->push_read(chunk => int($1), sub {
my ($_h, $_data) = @_;
$self->_reply($_h, $req, $hdr, $_data);
});
} else {
$self->_reply($h, $req, $hdr);
lib/Test/HTTP/AnyEvent/Server.pm view on Meta::CPAN
return;
} default {
my $found;
if ($self->custom_handler) {
$res->request(HTTP::Request->new(
$method,
$uri,
[
map {
m{^\s*([^:\s]+)\s*:\s*(.*)$}sx
} split m{\015?\012}x, $hdr
],
$content,
));
$found = eval { $self->custom_handler->($res) };
if ($@) {
AE::log error => "custom_handler died: $@";
$res->code(&HTTP::Status::RC_INTERNAL_SERVER_ERROR);
$res->content($@);
$found = 1;
}
( run in 1.858 second using v1.01-cache-2.11-cpan-71847e10f99 )