dian has asked for the wisdom of the Perl Monks concerning the following question:

I am trying to use get (or head) on an HTTPS address. It's working fine as long as I don't have a proxy configured on my machine (proxy environment variable https_proxy). I have tried with LWP::simple and LWP::userAgent. Following environment variable exists on my machine:
http_proxy=http://www-proxy.companyDomain:8080/ https_proxy=http://www-proxy.companyDomain:8080/ no_proxy=localhost, 127.0.0.1, .companyDomain
If I am testing towards HTTP it works fine.
If I am testing towards HTTP and remove the environment variable "no_proxy", it doesn't work (as expected). To me, thats a kind of proof that both "http_proxy" and "no_proxy" env variables are (indirectly) used by my script.
If I test towards HTTPS and remove the "https_proxy" env variable, then it works fine (no matter if the "no_proxy" env variable is there or not). To me thats a kind of proof that the env vaiable "no_proxy" isn't used when I am testing towards an HTTPS address.

Finally, I did another test. I was using wget directly from the linux shell (towards the same HTTPS-address), and it was working. Thats why I think I have noticed a limitation or bug in LWP (OR I might be using it the wrong way).
Note that I don't do anything read the environment variables to the script (from the machine). I thought I had to, but it seems to be done automatically (well, except for "no_proxy" when using https. I have tried different alternatives to import the environment variables to the script, but with no success.
I am using perl5.8.9 on a linux.

Here is how my script looks like:
use strict; use warnings; use LWP::UserAgent; my $address = "https://companyDomain/subpage"; # Start useragent and get the webpage my $ua = new LWP::UserAgent; my $head_request = new HTTP::Request GET => $address; my $head_response = $ua->request( $head_request ); # Evaluate result if ($head_response->is_success){ print " is valid\n"; } else { print ": is invalid\n"; }
I mentioned I have tried to use a number of ways to be able to solve this(one at a time), for example:
$ENV{HTTPS_PROXY} = ''; $ua->proxy(['http', 'https'] => ''); $ua->no_proxy(".companyDomain"); $ua->env_proxy('no_proxy=.companyDomain');
Anyone who has some thoughts/ideas/suggestions? Solution or workaround? If not with LWP, so Perhaps a solution with another module.

Replies are listed 'Best First'.
Re: LWP https problem with no_proxy
by daxim (Curate) on Mar 11, 2013 at 12:13 UTC
    Works for me.

    plackup -e'sub{[200,[],[]]}'
    starts a dummy Web server at localhost:5000. It doesn't proxy, it doesn't even do anything useful, but that's not important, the point is that it logs some output when it receives a request.

    http_proxy=http://localhost:5000 no_proxy=perlmonks.org perl -mLWP::UserAgent -e'my $ua = LWP::UserAgent->new; $ua->env_proxy; $ua->get("http://example.net")'
    gives error output from the dummy proxy - the LWP client tries to talk through the proxy.

    http_proxy=http://localhost:5000 no_proxy=perlmonks.org perl -mLWP::UserAgent -e'my $ua = LWP::UserAgent->new; $ua->env_proxy; $ua->get("http://perlmonks.org/index.pl?node_id=1022784")'
    gives no output from the dummy proxy - it is by-passed.

Re: LWP https problem with no_proxy
by dian (Initiate) on Mar 11, 2013 at 13:35 UTC
    I did find a workaround, so I am not in a dire need of help anymore. I am however curious if this is a fault or not (and if I can use LWP differently and get it to work). I added following line of code to get it work:
    delete $ENV{https_proxy};