libwww-perl
view release on metacpan or search on metacpan
t/base/ua.t view on Meta::CPAN
User-Agent: foo/0.1
Content-Length: 8
Content-Type: application/x-www-form-urlencoded
Foo: bar
Multi: 1
Multi: 2
x=y&f=ff
EOT
is(ref($clone->{proxy}), 'HASH', 'ref($clone->{proxy})');
is($ua->proxy(http => undef), "loopback:", '$ua->proxy(http => undef)');
is($ua->proxy('http'), undef, "\$ua->proxy('http')");
my $res = $ua->get("data:text/html,%3Chtml%3E%3Chead%3E%3Cmeta%20http-equiv%3D%22Content-Script-Type%22%20content%3D%22text%2Fjavascript%22%3E%3Cmeta%20http-equiv%3D%22Content-Style-Type%22%20content%3D%22text%2Fcss%22%3E%3C%2Fhead%3E%3C%2Fhtml%3E");
ok($res->header("Content-Style-Type", "text/css"), '$res->header("Content-Style-Type", "text/css")');
ok($res->header("Content-Script-Type", "text/javascript"), '$res->header("Content-Script-Type", "text/javascript")');
is(join(":", $ua->ssl_opts), "verify_hostname", '$ua->ssl_opts');
is($ua->ssl_opts("verify_hostname"), 1, '$ua->ssl_opts("verify_hostname")');
is($ua->ssl_opts("verify_hostname" => 0), 1, '$ua->ssl_opts("verify_hostname" => 0)');
is($ua->ssl_opts("verify_hostname"), 0, '$ua->ssl_opts("verify_hostname")');
is($ua->ssl_opts("verify_hostname" => undef), 0, '$ua->ssl_opts("verify_hostname" => undef)');
is($ua->ssl_opts("verify_hostname"), undef, '$ua->ssl_opts("verify_hostname")');
is(join(":", $ua->ssl_opts), "", '$ua->ssl_opts');
$ua = LWP::UserAgent->new(ssl_opts => {});
is($ua->ssl_opts("verify_hostname"), 1, '$ua->ssl_opts("verify_hostname")');
$ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 });
is($ua->ssl_opts("verify_hostname"), 0, '$ua->ssl_opts("verify_hostname")');
$ua = LWP::UserAgent->new(ssl_opts => { SSL_ca_file => 'cert.dat'});
is($ua->ssl_opts("verify_hostname"), 1, '$ua->ssl_opts("verify_hostname")');
is($ua->ssl_opts("SSL_ca_file"), 'cert.dat', '$ua->ssl_opts("SSL_ca_file")');
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 1;
$ua = LWP::UserAgent->new();
is($ua->ssl_opts("verify_hostname"), 1, '$ua->ssl_opts("verify_hostname")');
$ua = LWP::UserAgent->new(ssl_opts => {});
is($ua->ssl_opts("verify_hostname"), 1, '$ua->ssl_opts("verify_hostname")');
$ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 });
is($ua->ssl_opts("verify_hostname"), 0, '$ua->ssl_opts("verify_hostname")');
$ENV{PERL_LWP_SSL_VERIFY_HOSTNAME} = 0;
$ua = LWP::UserAgent->new();
is($ua->ssl_opts("verify_hostname"), 0, '$ua->ssl_opts("verify_hostname")');
$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();
is($ua->proxy('http'), "http://example.com", "\$ua->proxy('http')");
$ua = LWP::UserAgent->new(env_proxy => 0);
is($ua->proxy('http'), undef, "\$ua->proxy('http')");
$ua = LWP::UserAgent->new();
is($ua->conn_cache, undef, "\$ua->conn_cache");
$ua = LWP::UserAgent->new(keep_alive => undef);
is($ua->conn_cache, undef, "\$ua->conn_cache");
$ua = LWP::UserAgent->new(keep_alive => 0);
is($ua->conn_cache, undef, "\$ua->conn_cache");
$ua = LWP::UserAgent->new(keep_alive => 1);
is($ua->conn_cache->total_capacity, 1, "\$ua->conn_cache->total_capacity");
done_testing();
( run in 1.260 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )