I made a patch.
Patching:
cd LWP-Protocol-socks-1.3 && patch -p1 < LWP-Protocol-socks-1.3.patch
Usage:
$ua->proxy(['http', 'https'] => 'socks4://localhost:1080'); # socks4
$ua->proxy(['http', 'https'] => 'socks://localhost:1080'); # socks5
And one possible bugfix in this patch. For http schema it was double
connection to the proxy server. Hack from the https part of the module
solved the problem.
diff -Naur LWP-Protocol-socks-1.3//lib/LWP/Protocol/socks4.pm LWP-Protocol-socks-1.3-patched//lib/LWP/Protocol/socks4.pm
--- LWP-Protocol-socks-1.3//lib/LWP/Protocol/socks4.pm 1970-01-01 07:00:00.000000000 +0700
+++ LWP-Protocol-socks-1.3-patched//lib/LWP/Protocol/socks4.pm 2011-02-05 20:22:11.000000000 +0600
@@ -0,0 +1,24 @@
+package LWP::Protocol::socks4;
+require LWP::Protocol::socks;
+our @ISA = qw(LWP::Protocol);
+
+sub request {
+ my($self, $request, $proxy, $arg, $size, $timeout) = @_;
+ my $url = $request->uri;
+ my $scheme = $url->scheme;
+ my $protocol = LWP::Protocol::create("$scheme\::socks", $self->{ua});
+ $protocol->{proxy_sock_opts} = [ProxyAddr => $proxy->host,
+ ProxyPort => $proxy->port,
+ SocksVersion => 4
+ ];
+
+ if ( $proxy->userinfo() ) {
+ push(@{$protocol->{proxy_sock_opts}},
+ Username => $proxy->user()
+ );
+ }
+
+ $protocol->request($request, undef, $arg, $size, $timeout);
+}
+
+1;
diff -Naur LWP-Protocol-socks-1.3//lib/LWP/Protocol/socks.pm LWP-Protocol-socks-1.3-patched//lib/LWP/Protocol/socks.pm
--- LWP-Protocol-socks-1.3//lib/LWP/Protocol/socks.pm 2010-07-24 02:19:28.000000000 +0700
+++ LWP-Protocol-socks-1.3-patched//lib/LWP/Protocol/socks.pm 2011-02-05 20:29:44.993206258 +0600
@@ -37,6 +37,11 @@
$self->http_configure($args);
}
+# hack out the connect so it doesn't reconnect
+sub http_connect {
+ 1;
+}
+
##############################
package LWP::Protocol::https::socks;
require LWP::Protocol::https;
diff -Naur LWP-Protocol-socks-1.3//lib/URI/socks4.pm LWP-Protocol-socks-1.3-patched//lib/URI/socks4.pm
--- LWP-Protocol-socks-1.3//lib/URI/socks4.pm 1970-01-01 07:00:00.000000000 +0700
+++ LWP-Protocol-socks-1.3-patched//lib/URI/socks4.pm 2011-02-05 20:23:22.000000000 +0600
@@ -0,0 +1,6 @@
+package URI::socks4;
+require URI::socks;
+
+our @ISA = qw(URI::socks);
+
+1;