Skip to content

Instantly share code, notes, and snippets.

@tim-2
Created June 14, 2016 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tim-2/27baa4055c725e3bce57eb0ad589e609 to your computer and use it in GitHub Desktop.
Save tim-2/27baa4055c725e3bce57eb0ad589e609 to your computer and use it in GitHub Desktop.
diff --git a/lib/Mojo/IOLoop/Client.pm b/lib/Mojo/IOLoop/Client.pm
index 831b308..377ef54 100644
--- a/lib/Mojo/IOLoop/Client.pm
+++ b/lib/Mojo/IOLoop/Client.pm
@@ -146,7 +146,7 @@ sub _try_socks {
error => 'IO::Socket::Socks 0.64+ required for SOCKS support')
unless SOCKS;
- my %options = (ConnectAddr => $args->{address}, ConnectPort => $args->{port});
+ my %options = (ConnectAddr => $args->{address}, ConnectPort => $args->{port}, SocksVersion => $args->{socks_version});
@options{qw(AuthType Username Password)}
= ('userpass', @$args{qw(socks_user socks_pass)})
if $args->{socks_user};
diff --git a/lib/Mojo/UserAgent.pm b/lib/Mojo/UserAgent.pm
index fc9e080..1a3c51e 100644
--- a/lib/Mojo/UserAgent.pm
+++ b/lib/Mojo/UserAgent.pm
@@ -85,8 +85,8 @@ sub _connect {
$options{handle} = $handle if $handle;
# SOCKS
- if ($proto eq 'socks') {
- @options{qw(socks_address socks_port)} = @options{qw(address port)};
+ if ($proto =~ /socks([45])?/) {
+ @options{qw(socks_address socks_port socks_version)} = (@options{qw(address port)}, $1 // 5);
($proto, @options{qw(address port)}) = $t->endpoint($tx);
my $userinfo = $tx->req->via_proxy(0)->proxy->userinfo;
@options{qw(socks_user socks_pass)} = split ':', $userinfo if $userinfo;
diff --git a/lib/Mojo/UserAgent/Transactor.pm b/lib/Mojo/UserAgent/Transactor.pm
index 0104b02..24b2093 100644
--- a/lib/Mojo/UserAgent/Transactor.pm
+++ b/lib/Mojo/UserAgent/Transactor.pm
@@ -31,7 +31,7 @@ sub endpoint {
# Proxy for normal HTTP requests
my $socks;
- if (my $proxy = $req->proxy) { $socks = $proxy->protocol eq 'socks' }
+ if (my $proxy = $req->proxy) { $socks = $proxy->protocol =~ /socks[45]?/ }
return $self->_proxy($tx, $proto, $host, $port)
if $proto eq 'http' && !$req->is_handshake && !$socks;
@@ -49,7 +49,7 @@ sub proxy_connect {
# No proxy
return undef unless (my $proxy = $req->proxy) && $req->via_proxy;
- return undef if $proxy->protocol eq 'socks';
+ return undef if $proxy->protocol =~ /socks[45]?/;
# WebSocket and/or HTTPS
my $url = $req->url;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment