IO::Lambda::HTTP - http requests lambda style
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 an error string otherwise.
use HTTP::Request; use IO::Lambda qw(:all); use IO::Lambda::HTTP qw(http_request);
lambda { context shift; http_request { my $result = shift; if ( ref($result)) { print "good: ", length($result-> content), " bytes\n"; } else { print "bad: $result\n"; } } }-> wait( HTTP::Request-> new( GET => "http://www.perl.com/") );
http_request is a lambda predicate that accepts HTTP::Request object in
the context. Returns either a HTTP::Response object on success, or error
string otherwise.
Stores HTTP::Request object and returns a new lambda that will finish when
the associated request completes. The lambda will return either a
HTTP::Response object on success, or an error string otherwise.
If set, hostname will be resolved with the IO::Lambda::DNS manpage using asynchronous the Net::DNS manpage. Note that this method won't be able to account for non-DNS (/etc/hosts, NIS) host names.
If unset (default), hostnames will be resolved in a blocking manner.
Normally, a request is sent without any authentication. The authentication
is only tried after a 401 error is returned. To avoid this first stage,
knowing in advance the type of authentication that shall be accepted by the
remote, option auth can be used.
username => 'user', password => 'pass', auth => 'Basic',
The requestor can optionally use a LWP::ConnCache object to reuse
connections on per-host per-port basis. Desired for HTTP/1.1. Required for
NTLM authentication. See the LWP::ConnCache manpage for details.
Aborts a request and returns 'timeout' string if it is not finished
by the given deadline (in epoch seconds). If undef, no timeouts occur.
If set, all incoming requests are silently converted to use HTTP/1.1, and connections are reused. Same as a combination of the following:
$req-> protocol('HTTP/1.1'); $req-> headers-> header( Host => $req-> uri-> host); new( $req, conn_cache => LWP::ConnCache-> new);
Maximum allowed redirects. If 0, no redirection attemps are made.
List of preferred authentication methods, used to choose the authentication method where there are more than one supported by the server. When the value is a string, the given method is tried first, and then all available methods. When it is a hash, its values are treated as weight factors, - the method with the greatest weight is tried first. Negative values prevent the corresponding methods from being tried.
# try basic and whatever else
preferred_auth => 'Basic',
# try basic and never ntlm
preferred_auth => {
Basic => 1,
NTLM => -1,
},
Note that the current implementation doesn't provide re-trying of authentication if either a method or username/password combination fails. When at least one method was declared by the remote as supported, and was tried and failed, no further retries are made.
If set, HOSTNAME (or HOSTNAME and PORT tuple) is used as HTTP proxy settings.
Maximum allowed time the request can take. If undef, no timeouts occur.
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.
the IO::Lambda manpage, the HTTP::Request manpage, the HTTP::Response manpage
Dmitry Karasik, <dmitry@karasik.eu.org>.