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

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.

auth $AUTH

Normally, a request is sent without any authentication, and a 401 error is returned, the next step is to try authentication methods. To avoid this first stage, and send the authentication to the remote, auth can be used.

username => 'user',
password => 'pass',
auth     => 'Basic',
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, where many are supported by the server. When a single string, this method is tried first, then all available methods. When a hash, its values are treated as weight factors, -- the method with greatest factor is tried first. Negative values exclude corresponding methods from trying.

     # try basic and whatever else
     preferred_auth => 'Basic',

     # try basic and never ntlm
     preferred_auth => {
         Basic => 1,
	 NTLM  => -1,
     },
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>.