POE-Component-Client-HTTP
view release on metacpan or search on metacpan
README.mkdn view on Meta::CPAN
# NAME
POE::Component::Client::HTTP - a HTTP user-agent component
# VERSION
version 0.949
# SYNOPSIS
use POE qw(Component::Client::HTTP);
POE::Component::Client::HTTP->spawn(
Agent => 'SpiffCrawler/0.90', # defaults to something long
Alias => 'ua', # defaults to 'weeble'
From => 'spiffster@perl.org', # defaults to undef (no header)
Protocol => 'HTTP/0.9', # defaults to 'HTTP/1.1'
Timeout => 60, # defaults to 180 seconds
MaxSize => 16384, # defaults to entire response
Streaming => 4096, # defaults to 0 (off)
FollowRedirects => 2, # defaults to 0 (off)
Proxy => "http://localhost:80", # defaults to HTTP_PROXY env. variable
NoProxy => [ "localhost", "127.0.0.1" ], # defs to NO_PROXY env. variable
BindAddr => "12.34.56.78", # defaults to INADDR_ANY
);
$kernel->post(
'ua', # posts to the 'ua' alias
'request', # posts to ua's 'request' state
'response', # which of our states will receive the response
$request, # an HTTP::Request object
);
# This is the sub which is called when the session receives a
# 'response' event.
sub response_handler {
my ($request_packet, $response_packet) = @_[ARG0, ARG1];
# HTTP::Request
my $request_object = $request_packet->[0];
# HTTP::Response
my $response_object = $response_packet->[0];
my $stream_chunk;
if (! defined($response_object->content)) {
$stream_chunk = $response_packet->[1];
}
print(
"*" x 78, "\n",
"*** my request:\n",
"-" x 78, "\n",
$request_object->as_string(),
"*" x 78, "\n",
"*** their response:\n",
"-" x 78, "\n",
$response_object->as_string(),
);
if (defined $stream_chunk) {
print "-" x 40, "\n", $stream_chunk, "\n";
}
print "*" x 78, "\n";
}
# DESCRIPTION
POE::Component::Client::HTTP is an HTTP user-agent for POE. It lets
other sessions run while HTTP transactions are being processed, and it
lets several HTTP transactions be processed in parallel.
It supports keep-alive through POE::Component::Client::Keepalive,
which in turn uses POE::Component::Resolver for asynchronous IPv4 and
IPv6 name resolution.
HTTP client components are not proper objects. Instead of being
created, as most objects are, they are "spawned" as separate sessions.
To avoid confusion (and hopefully not cause other confusion), they
must be spawned with a `spawn` method, not created anew with a `new`
one.
( run in 0.482 second using v1.01-cache-2.11-cpan-71847e10f99 )