Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Autodetect Proxy on Windows

by Takamoto (Beadle)
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:

Hello

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'], 'http://127.0.0.1:8888/'); my $url="https://www.google.com"; 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="https://www.google.com"; 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

    Takamoto:

    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.

    ...roboticus

    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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (7)
As of 2019-10-16 17:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?