AnyEvent-HTTP-Socks
view release on metacpan or search on metacpan
lib/AnyEvent/HTTP/Socks.pm view on Meta::CPAN
=head1 DESCRIPTION
This module adds new `socks' option to all http_* functions exported by AnyEvent::HTTP.
So you can specify socks proxy for HTTP requests.
This module uses IO::Socket::Socks as socks library, so any global variables like
$IO::Socket::Socks::SOCKS_DEBUG can be used to change the behavior.
Socks string structure is:
scheme://login:password@host:port
^^^^^^ ^^^^^^^^^^^^^^ ^^^^ ^^^^
1 2 3 4
1 - scheme can be one of the: socks4, socks4a, socks5
2 - "login:password@" part can be ommited if no authorization for socks proxy needed. For socks4
proxy "password" should be ommited, because this proxy type doesn't support login/password authentication,
login will be interpreted as userid.
3 - ip or hostname of the proxy server
4 - port of the proxy server
You can also make connection through a socks chain. Simply specify several socks proxies in the socks string
and devide them by tab(s) or space(s):
"socks4://10.0.0.1:1080 socks5://root:123@10.0.0.2:1080 socks4a://85.224.100.1:9010"
};
$loop->begin;
http_get "http://$h_host:$h_port/", socks => "socks5://$s3_host:$s3_port -> socks4://$s1_host:$s1_port", sub {
is($_[0], 'ROOT', 'socks5 -> socks4 chain');
$loop->end;
};
$loop->begin;
http_get "http://$h_host:$h_port/index", socks => "socks5://$s3_host:$s3_port socks5://xxx:xxx\@$s2_host:$s2_port", sub {
is($_[0], undef, 'socks5 -> socks5[auth] chain with bad password');
$loop->end;
};
$loop->begin;
http_get "http://$h_host:$h_port/index", socks => "socks5://$s3_host:$s3_port socks5://root:toor\@$s2_host:$s2_port", sub {
is($_[0], 'INDEX', 'socks5 -> socks5[auth] chain with good password');
$loop->end;
};
$loop->end;
$loop->recv;
kill 15, $_ for ($h_pid, $s1_pid, $s2_pid, $s3_pid, $s4_pid);
done_testing();
sub make_socks_server {
my ($version, $login, $password, %delay) = @_;
my $serv = IO::Socket::Socks->new(Listen => 3, SocksVersion => $version, RequireAuth => ($login && $password), UserAuth => sub {
return $_[0] eq $login && $_[1] eq $password;
}) or die $@;
my $child = fork();
die 'fork: ', $! unless defined $child;
if ($child == 0) {
while (1) {
if ($delay{accept}) {
sleep $delay{accept};
}
( run in 1.066 second using v1.01-cache-2.11-cpan-49f99fa48dc )