libwww-perl
view release on metacpan or search on metacpan
6.05 2013-03-11
- Derive message from status code if it was not provided
- Merge pull request #33 from tomhukins/fix-readme
- fix typo in comment
- Spelling fixes.
- Spelling fix.
- Merge pull request #34 from berekuk/fix-github-path
- Update repo URL
- With Net::HTTP 6.04 we don't need our own can_read() and sysread override
- $ENV{HTTP_PROXY} might override our test setup [RT#81381]
- fix github url in perldoc
- * Pod is utf-8
- Match required perl in Makefile.PL
- Fix Github URLs
6.04 2012-02-18
- Typo fix; envirionment [RT#72386]
- Implement $ua->is_online test
- Add separate option to enable the live jigsaw tests
- Merge pull request #10 from trcjr/master
- If the server output multiple Location headers on a redirect, ignore all
but the first one.
- Extract cookies failed on request URIs with empty paths. This was only
triggered if you used URI objects directly in scripts.
- This change was actually part of 5.51: Fix qop="auth" handling for Digest
authentication. Patch by Dave Dunkin <dave_dunkin@hotmail.com>.
5.51 2001-03-14
- SECURITY FIX:
If LWP::UserAgent::env_proxy is called in a CGI environment, the
case-insensitivity when looking for "http_proxy" permits "HTTP_PROXY"
to be found, but this can be trivially set by the web client using the
"Proxy:" header. The fix applied is that $ENV{HTTP_PROXY} is not longer
honored for CGI scripts. The CGI_HTTP_PROXY environment variable can be
used instead. Problem reported by Randal L. Schwartz.
- NOTE: It is recommended that everybody that use LWP::UserAgent (including
LWP::Simple) in CGI scripts upgrade to this release.
- Explicit setting of action on HTML::Form had no effect because of a code
typo. Patch by BooK <book@netcourrier.com>.
- HTTP::Daemon: The CONNECT method need special treatment because it does
not provide a URI as argument (just a "hostname:port"). The non-upward
compatibility warning is that you must now call $request->url->host_port
to get the host/port string for CONNECT, rather than calling
$request->url and using the entire string. Based on patch from
lib/LWP/UserAgent.pm view on Meta::CPAN
require Encode;
require Encode::Locale;
my $env_request_method= $ENV{REQUEST_METHOD};
my %seen;
foreach my $k (sort keys %ENV) {
my $real_key= $k;
my $v= $ENV{$k}
or next;
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);
if (my $from_key= $seen{$k}) {
# Only warn about proxy-related env vars, not unrelated ones (GH #372)
if ($k =~ /^(.*)_proxy$/) {
warn "Environment contains multiple differing definitions for '$k'.\n".
"Using value from '$from_key' ($ENV{$from_key}) and ignoring '$real_key' ($v)"
if $v ne $ENV{$from_key};
}
next;
lib/LWP/UserAgent.pm view on Meta::CPAN
gopher_proxy=http://proxy.example.org/
wais_proxy=http://proxy.example.org/
no_proxy="localhost,example.com"
export gopher_proxy wais_proxy no_proxy
csh or tcsh users should use the C<setenv> command to define these
environment variables.
On systems with case insensitive environment variables there exists a
name clash between the CGI environment variables and the C<HTTP_PROXY>
environment variable normally picked up by C<env_proxy>. Because of
this C<HTTP_PROXY> is not honored for CGI scripts. The
C<CGI_HTTP_PROXY> environment variable can be used instead.
=head2 no_proxy
$ua->no_proxy( @domains );
$ua->no_proxy('localhost', 'example.com');
$ua->no_proxy(); # clear the list
Do not proxy requests to the given domains, including subdomains.
Calling C<no_proxy> without any domains clears the list of domains.
##########################################################################
=head2 Using Proxies
In some cases, you will want to (or will have to) use proxies for
accessing certain sites and/or using certain protocols. This is most
commonly the case when your LWP program is running (or could be running)
on a machine that is behind a firewall.
To make a browser object use proxies that are defined in the usual
environment variables (C<HTTP_PROXY>, etc.), just call the C<env_proxy>
on a user-agent object before you go making any requests on it.
Specifically:
use LWP::UserAgent;
my $browser = LWP::UserAgent->new;
# And before you go making any requests:
$browser->env_proxy;
For more information on proxy parameters, see L<the LWP::UserAgent
t/base/proxy.t view on Meta::CPAN
use strict;
use warnings;
use Test::More;
use Test::Fatal qw( exception );
use LWP::UserAgent ();
plan tests => 8;
# in case already defined in user's environment
delete $ENV{$_} for qw(REQUEST_METHOD HTTP_PROXY http_proxy CGI_HTTP_PROXY NO_PROXY no_proxy);
for my $varname ( qw(ABSURDLY_NAMED_PROXY MY_PROXY) ) {
$ENV{ $varname } = "foobar";
my $ua = LWP::UserAgent->new;
is(exception{ $ua->env_proxy(); }, undef, "proxy: with env: $varname: no errors");
delete $ENV{$varname};
}
# simulate CGI environment
{
local $ENV{REQUEST_METHOD} = 'GET';
local $ENV{HTTP_PROXY} = 'something';
my $ua = LWP::UserAgent->new;
$ua->env_proxy();
is $ua->proxy('http'), undef, 'HTTP_PROXY ignored in CGI environment';
}
{
local $ENV{REQUEST_METHOD} = 'GET';
local $ENV{CGI_HTTP_PROXY} = 'http://proxy.example.org:3128/';
my $ua = LWP::UserAgent->new;
$ua->env_proxy();
is $ua->proxy('http'), 'http://proxy.example.org:3128/',
'substitute CGI_HTTP_PROXY used in CGI environment';
}
SKIP: {
skip "Environment variables are case-sensitive on this platform", 1
if do {
local $ENV{TEST_CASE_SENSITIVITY} = "a";
local $ENV{test_case_sensitivity} = "b";
$ENV{TEST_CASE_SENSITIVITY} eq $ENV{test_case_sensitivity};
};
my @warnings;
local $SIG{__WARN__} = sub { push @warnings, @_ };
local $ENV{HTTP_PROXY} = 'http://uppercase-proxy.example.org:3128/';
local $ENV{http_proxy} = 'http://lowercase-proxy.example.org:3128/';
my $ua = LWP::UserAgent->new;
$ua->env_proxy();
(my $warnings = "@warnings") =~ s{ at .*\n}{};
is $warnings, qq{Environment contains multiple differing definitions for 'http_proxy'.\nUsing value from 'HTTP_PROXY' (http://uppercase-proxy.example.org:3128/) and ignoring 'http_proxy' (http://lowercase-proxy.example.org:3128/)},
'expected warning on multiple definitions';
}
{
my @warnings;
local $SIG{__WARN__} = sub { push @warnings, @_ };
local $ENV{HTTP_PROXY} = 'http://proxy.example.org:3128/';
local $ENV{http_proxy} = 'http://proxy.example.org:3128/';
my $ua = LWP::UserAgent->new;
$ua->env_proxy();
is_deeply \@warnings, [],
"No warnings if multiple definitions for 'http_proxy' exist, but with the same value";
}
{
local $ENV{NO_PROXY} = 'localhost,example.com';
my $ua = LWP::UserAgent->new;
t/base/ua.t view on Meta::CPAN
$ua = LWP::UserAgent->new(ssl_opts => {});
is($ua->ssl_opts("verify_hostname"), 0, '$ua->ssl_opts("verify_hostname")');
$ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 1 });
is($ua->ssl_opts("verify_hostname"), 1, '$ua->ssl_opts("verify_hostname")');
delete @ENV{grep /_proxy$/i, keys %ENV}; # clean out any proxy vars
SKIP: {
skip 'case insensitive ENV on Windows makes this fail', 3, if $^O eq 'MSWin32';
$ENV{HTTP_PROXY}= "http://example.com";
$ENV{http_proxy}= "http://otherexample.com";
my @warn;
local $SIG{__WARN__}= sub { my ($msg)= @_; $msg=~s/ at .*\z//s; push @warn, $msg };
# test that we get "HTTP_PROXY" when it is set and differs from "http_proxy".
$ua = LWP::UserAgent->new;
is($ua->proxy('http'), undef);
$ua = LWP::UserAgent->new(env_proxy => 1);
is($ua->proxy('http'), "http://example.com", q{proxy('http') returns URL});
is($warn[0],"Environment contains multiple differing definitions for 'http_proxy'.\n"
."Using value from 'HTTP_PROXY' (http://example.com) and ignoring 'http_proxy' (http://otherexample.com)");
}
# test that if only one of the two is set we can handle either.
for my $type ('http_proxy', 'HTTP_PROXY') {
delete $ENV{HTTP_PROXY};
delete $ENV{http_proxy};
$ENV{$type} = "http://example.com";
$ua = LWP::UserAgent->new;
is($ua->proxy('http'), undef, q{proxy('http') returns undef} );
$ua = LWP::UserAgent->new(env_proxy => 1);
is($ua->proxy('http'), "http://example.com", q{proxy('http') returns URL});
}
$ENV{PERL_LWP_ENV_PROXY} = 1;
$ua = LWP::UserAgent->new();
( run in 0.857 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )