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);
my $req = HTTP::Request-> new( GET => "http://www.perl.com/");
$req-> protocol('HTTP/1.1');
$req-> headers-> header( Host => $req-> uri-> host);
$req-> headers-> header( Connection => 'close');
this lambda {
context shift;
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.
SEE ALSO
IO::Lambda, HTTP::Request, HTTP::Response
AUTHOR
Dmitry Karasik, <dmitry@karasik.eu.org>.