summaryrefslogblamecommitdiff
path: root/lib/Net/Riak/Role/UserAgent.pm
blob: 9dacf96627a49dbd77ac9dcd43d8e55f2bf7b6b8 (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11





                                   




                                                            
 





                   
                  


                                

                         






                                                                               
                                     

                                         
          


                                                       




            
package Net::Riak::Role::UserAgent;

# ABSTRACT: useragent for Net::Riak

use Moose::Role;
use LWP::UserAgent;
use LWP::ConnCache;

our $CONN_CACHE;

sub connection_cache { $CONN_CACHE ||= LWP::ConnCache->new }

has ua_timeout => (
    is  => 'rw',
    isa => 'Int',
    default => 120
);

has useragent => (
    is      => 'rw',
    isa     => 'LWP::UserAgent',
    lazy    => 1,
    default => sub {
        my $self = shift;

        # The Links header Riak returns (esp. for buckets) can get really long,
        # so here increase the MaxLineLength LWP will accept (default = 8192)
        my %opts = @LWP::Protocol::http::EXTRA_SOCK_OPTS;
        $opts{MaxLineLength} = 65_536;
        @LWP::Protocol::http::EXTRA_SOCK_OPTS = %opts;

        my $ua = LWP::UserAgent->new(
            timeout => $self->ua_timeout,
            keep_alive => 1,
        );

        $ua->conn_cache(__PACKAGE__->connection_cache);

        $ua;
    }
);

1;