IO-Socket-Socks-Wrapper
view release on metacpan or search on metacpan
t/01_in_pkg.t view on Meta::CPAN
#!/usr/bin/env perl
use Test::More;
BEGIN { use_ok('IO::Socket::Socks::Wrapper') };
require 't/subs.pm';
use IO::Socket::Socks;
use strict;
warn '$IO::Socket::Socks::SOCKET_CLASS = ', $IO::Socket::Socks::SOCKET_CLASS, "\n";
$^W = 0;
$ENV{http_proxy} = $ENV{HTTP_PROXY} =
$ENV{https_proxy} = $ENV{HTTPS_PROXY} =
$ENV{all_proxy} = $ENV{ALL_PROXY} = undef;
SKIP: {
skip "fork, windows, sux" if $^O =~ /MSWin/i;
eval { require LWP::UserAgent; require LWP::Protocol::http; }
or skip "No LWP found";
my ($s_pid, $s_host, $s_port) = make_socks_server(4);
my ($h_pid, $h_host, $h_port) = make_http_server();
IO::Socket::Socks::Wrapper->import(
'LWP::Protocol::http::Socket' => {
ProxyAddr => $s_host,
ProxyPort => $s_port,
SocksVersion => 4
}
);
my $ua = LWP::UserAgent->new();
my $page = $ua->get("http://$h_host:$h_port/")->content;
skip "You are behind squid" if $page =~ /squid/i;
is($page, 'ROOT', 'LWP+Socks4+Server');
kill 15, $s_pid;
$page = $ua->get("http://$h_host:$h_port/")->content;
isnt($page, 'ROOT', 'LWP+Socks4-Server');
kill 15, $h_pid;
};
SKIP: {
skip "fork, windows, sux" if $^O =~ /MSWin/i;
eval { require Net::HTTP }
or skip "No Net::HTTP found";
my ($s_pid, $s_host, $s_port) = make_socks_server(5);
my ($h_pid, $h_host, $h_port) = make_http_server();
IO::Socket::Socks::Wrapper->import(
Net::HTTP:: => {
ProxyAddr => $s_host,
ProxyPort => $s_port
}
);
my $http = Net::HTTP->new(Host => $h_host, PeerPort => $h_port);
my $page;
eval {
$http->write_request(GET => '/index');
$http->read_response_headers();
$http->read_entity_body($page, 1024);
};
skip "You are behind squid" if $page =~ /squid/i;
is($page, 'INDEX', 'HTTP+Socks5+Server');
kill 15, $s_pid;
$http = Net::HTTP->new(Host => $h_host, PeerPort => $h_port);
$page = '';
eval {
( run in 1.176 second using v1.01-cache-2.11-cpan-71847e10f99 )