UniEvent::HTTP::UserAgent - non blocking HTTP user agent
my $ua = UniEvent::HTTP::UserAgent->new; my $uri = 'https://crazypanda.ru'; my $next; $next = sub { $ua->request({ uri => $uri, response_callback => sub { my (undef, $res, $err) = @_; die $err if $err; my $body = say $response->body; # extract somehow next link $uri = ...; $next = undef unless $uri; }, }); }; $next->(), UE::Loop->default->run while $uri; my $saved_cookies = $ua->to_string; # save cookies to file or database, and load them later my $ua = UniEvent::HTTP::UserAgent->new({ serialized => $saved_cookies, identity => 'my-identity', });
The user agent binds together low-level http request API and Protocol::HTTP::CookieJar. That way it is possible to do proper browser-like navigation on the Web, correcly handling cookie on transitions between pages including redirects.
In other words with UserAgent it possible to have web browsing sessions which outlive perl process by persisting session (Protocol::HTTP::CookieJar) on a storage, or examining or modifying intermediate cookies.
Creates new UserAgent object which will use $loop UniEvent::Loop.
$loop
%config includes:
%config
String of the previously serialized Protocol::HTTP::CookieJar.
How to identity UserAgent to the remote server. The default is something like
Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.111 Safari/537.36 UniEvent-HTTP/1.0
SSL context, see Net::SSLeay and "use_ssl" in UniEvent::Stream.
The uri of proxy for making http requests. Currenlty, only socks-proxy is supported
Make a request to the specified $uri, possibly injecting the required cookies from the stored sesssion.
$uri
See "populate" in Protocol::HTTP::CookieJar for the meaning of $context_uri and $top_level.
$context_uri
$top_level
UniEvent::HTTP::Client is returned.
Helper method to stringify current CookieJar. See "to_string" in Protocol::HTTP::CookieJar for details.
Get/set UserAgent identity.
Get/set proxy uri, see URI::XS.
Get/set ssl context, see Net::SSLeay and "use_ssl" in UniEvent::Stream.
Get/set CookieJar.
Return assiciated Protocol::HTTP::CookieJar object. It is possible to examine, query and modify current cookies via this object.
To install UniEvent::HTTP, copy and paste the appropriate command in to your terminal.
cpanm
cpanm UniEvent::HTTP
CPAN shell
perl -MCPAN -e shell install UniEvent::HTTP
For more information on module installation, please visit the detailed CPAN module installation guide.