package LWP::UserAgent;
use strict;
use vars qw(@ISA $VERSION);
require LWP::MemberMixin;
@ISA = qw(LWP::MemberMixin);
$VERSION = "5.817";
use HTTP::Request ();
use HTTP::Response ();
use HTTP::Date ();
use LWP ();
use LWP::Debug ();
use LWP::Protocol ();
use Carp ();
if ($ENV{PERL_LWP_USE_HTTP_10}) {
require LWP::Protocol::http10;
LWP::Protocol::implementor('http', 'LWP::Protocol::http10');
eval {
require LWP::Protocol::https10;
LWP::Protocol::implementor('https', 'LWP::Protocol::https10');
};
}
sub new
{
# Check for common user mistake
Carp::croak("Options to LWP::UserAgent should be key/value pairs, not hash reference")
if ref($_[1]) eq 'HASH';
my($class, %cnf) = @_;
LWP::Debug::trace('()');
my $agent = delete $cnf{agent};
my $from = delete $cnf{from};
my $timeout = delete $cnf{timeout};
$timeout = 3*60 unless defined $timeout;
my $use_eval = delete $cnf{use_eval};
$use_eval = 1 unless defined $use_eval;
my $parse_head = delete $cnf{parse_head};
$parse_head = 1 unless defined $parse_head;
my $show_progress = delete $cnf{show_progress};
my $max_size = delete $cnf{max_size};
my $max_redirect = delete $cnf{max_redirect};
$max_redirect = 7 unless defined $max_redirect;
my $env_proxy = delete $cnf{env_proxy};
my $cookie_jar = delete $cnf{cookie_jar};
my $conn_cache = delete $cnf{conn_cache};
my $keep_alive = delete $cnf{keep_alive};
Carp::croak("Can't mix conn_cache and keep_alive")
if $conn_cache && $keep_alive;
my $protocols_allowed = delete $cnf{protocols_allowed};
my $protocols_forbidden = delete $cnf{protocols_forbidden};
my $requests_redirectable = delete $cnf{requests_redirectable};
$requests_redirectable = ['GET', 'HEAD']
unless defined $requests_redirectable;
# Actually ""s are just as good as 0's, but for concision we'll just say:
Carp::croak("protocols_allowed has to be an arrayref or 0, not \"$protocols_allowed\"!")
if $protocols_allowed and ref($protocols_allowed) ne 'ARRAY';
Carp::croak("protocols_forbidden has to be an arrayref or 0, not \"$protocols_forbidden\"!")
if $protocols_forbidden and ref($protocols_forbidden) ne 'ARRAY';
Carp::croak("requests_redirectable has to be an arrayref or 0, not \"$requests_redirectable\"!")
if $requests_redirectable and ref($requests_redirectable) ne 'ARRAY';
if (%cnf && $^W) {
Carp::carp("Unrecognized LWP::UserAgent options: @{[sort keys %cnf]}");
}
my $self = bless {
def_headers => undef,
timeout => $timeout,
use_eval => $use_eval,
show_progress=> $show_progress,
max_size => $max_size,
max_redirect => $max_redirect,
proxy => {},
no_proxy => [],
protocols_allowed => $protocols_allowed,
protocols_forbidden => $protocols_forbidden,
requests_redirectable => $requests_redirectable,
}, $class;
$self->agent($agent || $class->_agent);
$self->from($from) if $from;
$self->cookie_jar($cookie_jar) if $cookie_jar;
$self->parse_head($parse_head);
$self->env_proxy if $env_proxy;
=1= |