for my $domain (@{$ua->{no_proxy}}) {
if ($host =~ /\Q$domain\E$/) {
return;
}
}
}
}
$req->{proxy} = $HTTP::URI_CLASS->new($proxy);
}
sub proxy
{
my $self = shift;
my $key = shift;
return map $self->proxy($_, @_), @$key if ref $key;
my $old = $self->{'proxy'}{$key};
if (@_) {
$self->{proxy}{$key} = shift;
$self->set_my_handler("request_preprepare", \&_need_proxy)
}
return $old;
}
sub env_proxy {
my ($self) = @_;
my($k,$v);
while(($k, $v) = each %ENV) {
if ($ENV{REQUEST_METHOD}) {
# Need to be careful when called in the CGI environment, as
# the HTTP_PROXY variable is under control of that other guy.
next if $k =~ /^HTTP_/;
$k = "HTTP_PROXY" if $k eq "CGI_HTTP_PROXY";
}
$k = lc($k);
next unless $k =~ /^(.*)_proxy$/;
$k = $1;
if ($k eq 'no') {
$self->no_proxy(split(/\s*,\s*/, $v));
}
else {
$self->proxy($k, $v);
}
}
}
sub no_proxy {
my($self, @no) = @_;
if (@no) {
push(@{ $self->{'no_proxy'} }, @no);
}
else {
$self->{'no_proxy'} = [];
}
}
sub _new_response {
my($request, $code, $message) = @_;
my $response = HTTP::Response->new($code, $message);
$response->request($request);
$response->header("Client-Date" => HTTP::Date::time2str(time));
$response->header("Client-Warning" => "Internal response");
$response->header("Content-Type" => "text/plain");
$response->content("$code $message\n");
return $response;
}
1;
__END__
=head1 NAME
LWP::UserAgent - Web user agent class
=head1 SYNOPSIS
require LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
my $response = $ua->get('http://search.cpan.org/');
if ($response->is_success) {
print $response->decoded_content; # or whatever
}
else {
die $response->status_line;
}
=head1 DESCRIPTION
The C<LWP::UserAgent> is a class implementing a web user agent.
=10= |