Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Autodetect Proxy on Windows

by Takamoto (Novice)
on Jan 11, 2019 at 12:12 UTC ( #1228394=perlquestion: print w/replies, xml ) Need Help??
Takamoto has asked for the wisdom of the Perl Monks concerning the following question:


I need to run scripts through a proxy on Windows machines. I usually do this:

use strict; use warnings; use LWP::UserAgent; use HTTP::Request; print "Connecting...\n"; my $ua = LWP::UserAgent->new( ); $ua->proxy(['http', 'https'], ''); my $url=""; my $req = HTTP::Request->new(GET => $url); my $response = $ua->request($req); if ($response->is_success) { print "OK CONNECTION!\n"; } else{ print "NO CONNECTION!\n"; }

This works fine. However, I would like to autodetect the proxy. The only thing I found so far is LWP::UserAgent::ProxyAny;. Changing the script to:

use strict; use warnings; use LWP::UserAgent::ProxyAny; use HTTP::Request; print "Connecting...\n"; my $ua = LWP::UserAgent::ProxyAny->new; $ua->env_proxy; my $url=""; my $req = HTTP::Request->new(GET => $url); my $response = $ua->request($req); if ($response->is_success) { print "OK CONNECTION!\n"; } else{ print "NO CONNECTION!\n"; }

I go through the proxy. If I look inside $ua I found my proxy. HOWEVER, the module is 15 years old, and normally I have lots of doubts in using modules that never get updated. So, before using it in production I would like to have some feedbacks from people using it and know possible problems I could face (and of course I am interested in alternatives, if any). Thank you.

Replies are listed 'Best First'.
Re: Autodetect Proxy on Windows
by roboticus (Chancellor) on Jan 11, 2019 at 14:13 UTC


    I understand why you might be worried: the module hasn't changed in a long time, the author hasn't updated any of their modules in a long time, and the package has little in the way of test coverage.

    In this case, though, I wouldn't worry about it: The module itself is just 80 lines of code that just verifies that it's running on windows, and if so, it looks in the registry for the proxy information. A quick google seems to indicate that looking in the registry is a common way to get proxy information, so I'd expect it to be a reasonable way to get the proxy information for the foreseeable future.


    When your only tool is a hammer, all problems look like your thumb.

      I also had a read through the distribution, and I agree with roboticus; it appears like it's fine to use.

      Very little complexity, so really nothing has had to be updated.

      There are no test failures, but with that said, there's only a few tests being run. Again though, the module is pretty simplistic in what it does.

Re: Autodetect Proxy on Windows
by Anonymous Monk on Jan 15, 2019 at 11:38 UTC

    I find the approach of LWP::UserAgent::ProxyAny; quite interesting. Is there something similar for macOS?!?

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1228394]
Front-paged by haukex
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2019-01-19 10:39 GMT
Find Nodes?
    Voting Booth?
    After Perl5, I'm mostly interested in:

    Results (338 votes). Check out past polls.