LWP::Protocol::AnyEvent::http - Event loop friendly HTTP/HTTPS/SOCKS backend for LWP
Version 1.14.0
# Make HTTP and HTTPS requests friendly to event loops. use LWP::Protocol::AnyEvent::http; # Or LWP::Simple, WWW::Mechanize, etc use LWP::UserAgent; # A reason to want LWP friendly to event loops. use Coro qw( async ); for my $url (@urls) { async { my $ua = LWP::UserAgent->new(); $ua->protocols_allowed([qw( http https )]); # The only protocols made safe. process( $ua->get($url) ); }; } # Using a worker pool model to fetch web pages in parallel. use Coro qw( async ); use Coro::Channel qw( ); use LWP::Protocol::AnyEvent::http qw( ); use LWP::UserAgent qw( ); my $num_workers = 10; my $q = Coro::Channel->new(); my @threads; for (1..$num_workers) { push @threads, async { my $ua = LWP::UserAgent->new(); $ua->protocols_allowed([qw( http https )]); while (my $url = $q->get()) { handle_response($ua->get($url)); } } } while (my $url = get_next_url()) { $q->put($url); } $q->shutdown(); $_->join() for @threads;
LWP performs a number of blocking calls when trying to process requests. This makes it unfriendly to event-driven systems and cooperative multitasking system such as Coro.
This module makes LWP more friendly to these systems by plugging in an HTTP, HTTPS and SOCKS protocol implementor powered by AnyEvent and AnyEvent::HTTP.
In short, it allows AnyEvent callbacks and Coro threads to execute when LWP is blocked. (Please let me know at <ikegami@adaelis.com> what other system this helps so I can add tests and add a mention.)
<ikegami@adaelis.com>
All LWP features and configuration options should still be available when using this module.
The following protocols are supported:
https: request and proxy
https
http: request and proxy
http
socks: alias for socks5
socks
socks5
socks5: proxy only
socks4a: proxy only
socks4a
socks4: proxy only
socks4
Only the following ssl_opts are currently supported:
ssl_opts
verify_hostname
SSL_verify_mode
Only partially supported. Unspecified or VERIFY_NONE disables verification, anything else enables it.
VERIFY_NONE
SSL_verifycn_scheme
Only www is supported. Any other value is ignored.
www
SSL_ca_file
SSL_ca_path
SSL_cert_file
SSL_cert
SSL_key_file
SSL_key
As with LWP::Protocol::https, if hostname verification is requested by LWP::UserAgent's ssl_opts, and neither SSL_ca_file nor SSL_ca_path is set, then SSL_ca_file is implied to be the one provided by Mozilla::CA.
The maintainer will be happy to add support for additional options.
LWP::Protocol::Coro::http
An earlier implementation of this module that requires Coro. These two modules are developed in parallel.
Coro
An excellent cooperative multitasking library assisted by this module.
AnyEvent, AnyEvent::HTTP, AnyEvent::HTTP::Socks
Powers this module.
LWP::Simple, LWP::UserAgent, WWW::Mechanize
Affected by this module.
Coro::LWP
An alternative to this module for users of Coro. Intrusive, which results in problems in some unrelated code. Doesn't support HTTPS. Supports FTP and NTTP.
AnyEvent::HTTP::LWP::UserAgent
An alternative to this module that attempts to provide the same interface as LWP::UserAgent, but falls short in many ways. Unlike AnyEvent::HTTP::LWP::UserAgent, this module only replaces the back end of LWP::UserAgent, offering a much more faithful experience.
Please report any bugs or feature requests to bug-LWP-Protocol-AnyEvent-http at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=LWP-Protocol-AnyEvent-http. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.
bug-LWP-Protocol-AnyEvent-http at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc LWP::Protocol::AnyEvent::http
You can also look for information at:
Search CPAN
http://search.cpan.org/dist/LWP-Protocol-AnyEvent-http
RT: CPAN's request tracker
http://rt.cpan.org/NoAuth/Bugs.html?Dist=LWP-Protocol-AnyEvent-http
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/LWP-Protocol-AnyEvent-http
CPAN Ratings
http://cpanratings.perl.org/d/LWP-Protocol-AnyEvent-http
Eric Brine, <ikegami@adaelis.com>, Maintainer
Max Maischein, <corion@cpan.org>
<corion@cpan.org>
Graham Barr, <gbarr@pobox.com>
<gbarr@pobox.com>
No rights reserved.
The author has dedicated the work to the Commons by waiving all of his or her rights to the work worldwide under copyright law and all related or neighboring legal rights he or she had in the work, to the extent allowable by law.
Works under CC0 do not require attribution. When citing the work, you should not imply endorsement by the author.
To install LWP::Protocol::AnyEvent::http, copy and paste the appropriate command in to your terminal.
cpanm
cpanm LWP::Protocol::AnyEvent::http
CPAN shell
perl -MCPAN -e shell install LWP::Protocol::AnyEvent::http
For more information on module installation, please visit the detailed CPAN module installation guide.