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);

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/")
);

API

http_request $HTTP::Request

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.

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 a HTTP::Response object on success, or error string otherwise.

OPTIONS

async_dns BOOLEAN

If set, hostname will be resolved with IO::Lambda::DNS using asynchronous Net::DNS. 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.

auth $AUTH

Normally, a request is sent without any authentication. When 401 error is returned, only then authentication is tried. To avoid this first stage, knowing in advance the type of authentication will be accepted by the remote, auth can be used.

username => 'user',
password => 'pass',
auth     => 'Basic',
conn_cache $LWP::ConnCache = undef

Can optionally use a LWP::ConnCache object to reuse connections on per-host per-port basis. Required for NTLM authentication. See LWP::ConnCache for details.

keep_alive BOOLEAN

If set, all incoming requests are silently converted to use HTTP/1.1, and connections are reused. Same as combined effect of explicitly setting

$req-> protocol('HTTP/1.1');
$req-> headers-> header( Host => $req-> uri-> host);
new( $req, conn_cache => LWP::ConnCache-> new);
max_redirect NUM = 7

Maximum allowed redirects. If 1, no redirection attemps are made.

preferred_auth $AUTH|%AUTH

List of preferred authentication methods, used to choose the authentication method in case when many are supported by the server. When option is a single 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 factor is tried first. Negative values exclude the corresponding methods from trying.

     # 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 will be made.

proxy HOSTNAME | [ HOSTNAME, PORT ]

If set, HOSTNAME (or HOSTNAME and PORT) are used as HTTP proxy settings.

timeout SECONDS = undef

Maximum allowed time the request can take. If undef, no timeouts occur.

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>.