NAME
IO::Lambda::HTTP - http requests lambda style
DESCRIPTION
The module exports a single predicate http_request
that accepts a HTTP::Request
object and set of options as parameters. Returns either a HTTP::Response
on success, or error string otherwise.
SYNOPSIS
use HTTP::Request;
use IO::Lambda qw(:all);
use IO::Lambda::HTTP qw(http_request);
use LWP::ConnCache;
# prepare http request
my $req = HTTP::Request-> new( GET => "http://www.perl.com/");
$req-> protocol('HTTP/1.1');
$req-> headers-> header( Host => $req-> uri-> host);
# connection cache (optional)
my $cache = LWP::ConnCache-> new;
this lambda {
context shift, conn_cache => $cache;
http_request {
my $result = shift;
if ( ref($result)) {
print "good:", length($result-> content), "\n";
} else {
print "bad:$result\n";
}
}
};
this-> wait($req);
API
- http_request $HTTP::Request
-
http_request
is a lambda predicate that acceptsHTTP::Request
object in the context. Returns either aHTTP::Response
object on success, or error string otherwise. - new $HTTP::Request
-
Stores
HTTP::Request
object and returns a new lambda that will finish when the request associated with it completes. The lambda callback will be passed either aHTTP::Response
object on success, or error string otherwise.
OPTIONS
- timeout SECONDS = undef
-
Maximum allowed time the request can take. If undef, no timeouts occur.
- max_redirect NUM = 7
-
Maximum allowed redirects. If 1, no redirection attemps are made.
- conn_cache $LWP::ConnCache = undef
-
Can optionally use a
LWP::ConnCache
object to reuse connections on per-host per-port basis. See LWP::ConnCache for details.
BUGS
Non-blocking connects, and hence the module, don't work on win32 on perl5.8.X due to under-implementation in ext/IO.xs . They do work on 5.10 however.
SEE ALSO
IO::Lambda, HTTP::Request, HTTP::Response
AUTHOR
Dmitry Karasik, <dmitry@karasik.eu.org>.