GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
AnyEvent::HTTP::LWP::UserAgent(3) User Contributed Perl Documentation AnyEvent::HTTP::LWP::UserAgent(3)

AnyEvent::HTTP::LWP::UserAgent - LWP::UserAgent interface but works using AnyEvent::HTTP

version 0.10

  use AnyEvent::HTTP::LWP::UserAgent;
  use Coro;

  my $ua = AnyEvent::HTTP::LWP::UserAgent->new;
  my @urls = (...);
  my @coro = map {
      my $url = $_;
      async {
          my $r = $ua->get($url);
          print "url $url, content " . $r->content . "\n";
      }
  } @urls;
  $_->join for @coro;

  # Or without Coro
  use AnyEvent::HTTP::LWP::UserAgent;
  use AnyEvent;

  my $ua = AnyEvent::HTTP::LWP::UserAgent->new;
  my @urls = (...);
  my $cv = AE::cv;
  $cv->begin;
  foreach my $url (@urls) {
      $cv->begin;
      $ua->get_async($url)->cb(sub {
          my $r = shift->recv;
          print "url $url, content " . $r->content . "\n";
          $cv->end;
      });
  }
  $cv->end;
  $cv->recv;

When you use Coro you have a choice: you can use Coro::LWP or AnyEvent::HTTP (if you want to make asynchronous HTTP requests). If you use Coro::LWP, some modules may work incorrectly (for example Cache::Memcached) because of global change of IO::Socket behavior. AnyEvent::HTTP uses different programming interface, so you must change more of your old code with LWP::UserAgent (and HTTP::Request and so on), if you want to make asynchronous code.

AnyEvent::HTTP::LWP::UserAgent uses AnyEvent::HTTP inside but have an interface of LWP::UserAgent. You can safely use this module in Coro environment (and possibly in AnyEvent too).

In plain AnyEvent, you may use _async methods. They don't make blocking wait but return condition variable. So, you can avoid recursive blocking wait error.

$ua->conn_cache
$ua->conn_cache($cache_obj)
New versions of "AnyEvent::HTTP" supports HTTP(S)/1.1 persistent connection, so you can control it in "AnyEvent::HTTP::LWP::UserAgent" using "conn_cache" method.

If you set "conn_cache" (as "LWP::ConnCache" object) then "Anyevent::HTTP::LWP::UserAgent" makes two things. In first it sets global variable $AnyEvent::HTTP::ACTIVE as you setted "total_capacity" for "conn_cache" (be careful: this have a global consequences, not local). And in the second "AnyEvent::HTTP::LWP::UserAgent" will create persistent connections if your $ua have "conn_cache" (local propery of $ua).

But you can't use remainder methods of your "conn_cache", all connections will contains in "AnyEvent::HTTP". $AnyEvent::HTTP::ACTIVE sets only when you set "conn_cache" for $ua. If you just change "total_capacity" of old "conn_cache" it will not change anything.

The following methods are async version of corresponding methods w/o _async suffix. Parameters are identical as originals. However, return value becomes condition variable. You can use it in a synchronous way by blocking wait

  $ua->simple_request_async(@args)->recv

or in an asynchronous way, also.

  $ua->simple_request_async(@args)->cb(sub { ... });
simple_request_async
request_async
get_async
post_async
head_async
put_async
delete_async

Some features of LWP::UserAgent can be broken ("protocols_forbidden" or something else). Precise documentation and realization of these features will come in the future.

You can use some AnyEvent::HTTP global function and variables. But use "agent" of UA instead of $AnyEvent::HTTP::USERAGENT and "max_redirect" instead of $AnyEvent::HTTP::MAX_RECURSE.

Content in request can be specified by code reference. This is the same as LWP::UserAgent but there are some limitations. LWP::UserAgent uses chunked encoding if Content-Length is not specified, while this module does NOT use chunked encoding even if Content-Length is not specified.

Content in response can be specified as filename or code reference. This is the same as LWP::UserAgent.

<http://github.com/tadam/AnyEvent-HTTP-LWP-UserAgent> Coro::LWP AnyEvent::HTTP LWP::Protocol::AnyEvent::http LWP::Protocol::Coro::http

Yasutaka Atarashi

Yury Zavarin <yury.zavarin@gmail.com>

This software is copyright (c) 2012 by Yury Zavarin.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

2012-12-10 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.