develooper Front page | perl.libwww | Postings from October 2011

Re: http_proxy

Thread Previous | Thread Next
From:
Gisle Aas
Date:
October 5, 2011 12:47
Subject:
Re: http_proxy
Message ID:
7F465EB6-B777-4C16-92FF-2B3479D1378F@activestate.com
On Oct 5, 2011, at 21:05 , Boyd Duffee wrote:

> Nigel Horne wrote:
>> On 5 Oct 2011, at 14:50, Boyd Duffee wrote:
>>> Hi there,
>>> 
>>> I'm writing a module SRU::Client and like a good boy, I wrote a test script (using Test::More).  I couldn't figure out why the test script would run on one machine, but not on another, until I found that the machine it wouldn't run on had the HTTP_PROXY set.  When I unset that variable in the shell, the script works, but I cannot for the life of me unset HTTP_PROXY in the script itself.
>>> 
>>> Things that don't work:
>>> undef $ENV{HTTP_PROXY}
>> Try:
>> delete $ENV{HTTP_PROXY};
> 
> I did.  No joy.
> 
> perl -MLWP::Simple -e 'delete $ENV{HTTP_PROXY}; print get("http://www.google.co.uk")'
> 
> doesn't work, but
> 
> unset HTTP_PROXY; perl -MLWP::Simple -e 'print get("http://www.google.co.uk")'
> 
> does work.

Your problem is that LWP::Simple calls $ua->env_proxy when it loads.  The -MLWP::Simple make perl load the module before the -e code runs.  You need to arrange for the environment variable to be deleted before that.  Deleting it in a BEGIN block is probably the way to go.  For instance like this:

   perl -e 'BEGIN{ delete $ENV{HTTP_PROXY} }; use LWP::Simple; print get("http://www.google.co.uk")'

--Gisle


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About