Hi,

I've been playing around with LWP::Simple over the past week
to snarf historical stock quotes from Yahoo for tax reporting.

Pleased with my feeble effort I wanted to share it with my
co-workers who may also need it and discovered the joys of
LWP and authenticating proxies.

Yes, doable but quite messy.  A colleage lamented the fact that
LWP::Simple (he's into one-liners) is not usable with auth proxies.  

Therefore, having a few free cycles, I taught UserAgent how to 
deal with this.  My version extracts the userinfo() portion of
the proxy URI.

I hope you find this patch useful.  I am by no means a Perl hacker, 
so feel free to modify to taste.

Usage:

# export http_proxy="http://proxyuser:[EMAIL PROTECTED]:port"

John Klar

patch is against:
# $Id: UserAgent.pm,v 1.77 2001/03/14 20:48:19 gisle Exp $
--- UserAgent.pm.orig   Wed Apr  4 15:33:50 2001
+++ UserAgent.pm        Wed Apr  4 15:41:27 2001
@@ -177,6 +177,16 @@
     my $proxy = $self->_need_proxy($url);
     if (defined $proxy) {
        $scheme = $proxy->scheme;
+
+       # Check the proxy URI's userinfo() for proxy credentials
+       # export http_proxy="http://proxyuser:proxypass@proxyhost:port"
+       my $p_auth = $proxy->userinfo();
+       if(defined $p_auth) {   
+               my ($p_user,$p_pass) = split(':',$p_auth);
+               LWP::Debug::debug("PROXY AUTH BASIC: user: $p_user, pass: $p_pass");
+               $request->proxy_authorization_basic($p_user,$p_pass);
+       }
+
     } else {
        $scheme = $url->scheme;
     }

Reply via email to