AnyEvent-HTTP-Socks
view release on metacpan or search on metacpan
lib/AnyEvent/HTTP/Socks.pm view on Meta::CPAN
undef $$timer;
return $c_cb->($sock);
}
if ($SOCKS_ERROR == SOCKS_WANT_WRITE) {
if ($w_type != WRITE_WATCHER) {
undef $$watcher;
$$watcher = AnyEvent->io(
fh => $sock,
poll => 'w',
cb => sub { _socks_handshake($cv, $watcher, WRITE_WATCHER, $timer, $sock, $chain, $c_host, $c_port, $c_cb) }
);
}
}
elsif ($SOCKS_ERROR == SOCKS_WANT_READ) {
if ($w_type != READ_WATCHER) {
undef $$watcher;
$$watcher = AnyEvent->io(
fh => $sock,
poll => 'r',
cb => sub { _socks_handshake($cv, $watcher, READ_WATCHER, $timer, $sock, $chain, $c_host, $c_port, $c_cb) }
);
}
}
else {
# unknown error
$@ = "IO::Socket::Socks: $SOCKS_ERROR";
undef $$watcher;
undef $$timer;
$c_cb->();
}
}
1;
__END__
=head1 NAME
AnyEvent::HTTP::Socks - Adds socks support for AnyEvent::HTTP
=head1 SYNOPSIS
use AnyEvent::HTTP;
use AnyEvent::HTTP::Socks;
http_get 'http://www.google.com/', socks => 'socks5://localhost:1080', sub {
print $_[0];
};
=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"
If you want to specify socks host as IPv6 address you need to use square brackets:
"socks5://[2a00:1450:400f:805::200e]:1080"
=head1 METHODS
=head2 AnyEvent::HTTP::Socks->inject('Package::Name')
Add socks support to some package based on AnyEvent::HTTP.
Example:
use AnyEvent::HTTP;
use AnyEvent::HTTP::Socks;
use AnyEvent::Google::PageRank qw(rank_get);
use strict;
AnyEvent::HTTP::Socks->inject('AnyEvent::Google::PageRank');
rank_get 'http://mail.com', socks => 'socks4://localhost:1080', sub {
warn $_[0];
};
=head1 NOTICE
You should load AnyEvent::HTTP::Socks after AnyEvent::HTTP, not before. Or simply load only AnyEvent::HTTP::Socks
and it will load AnyEvent::HTTP automatically.
=head1 SEE ALSO
L<AnyEvent::HTTP>, L<IO::Socket::Socks>
=head1 AUTHOR
Oleg G, E<lt>oleg@cpan.orgE<gt>
=head1 COPYRIGHT AND LICENSE
Copyright (C) 2011 by Oleg G
This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself
=cut
( run in 1.485 second using v1.01-cache-2.11-cpan-5b529ec07f3 )