UniEvent::HTTP::UserAgent - non blocking HTTP user agent


    my $ua = UniEvent::HTTP::UserAgent->new;
    my $uri = '';
    my $next; $next = sub {
            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.


new(\%config, [$loop = default])

Creates new UserAgent object which will use $loop UniEvent::Loop.

%config includes:


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

request($uri [, $context_uri = $uri, $top_level = true])

Make a request to the specified $uri, possibly injecting the required cookies from the stored sesssion.

See "populate" in Protocol::HTTP::CookieJar for the meaning of $context_uri and $top_level.

UniEvent::HTTP::Client is returned.

to_string([$include_session = false])

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.