--- loncom/LWPReq.pm 2016/07/25 19:49:45 1.2 +++ loncom/LWPReq.pm 2018/09/20 14:17:01 1.3 @@ -2,7 +2,7 @@ # LON-CAPA wrapper for LWP UserAgent to accommodate certification # verification for SSL. # -# $Id: LWPReq.pm,v 1.2 2016/07/25 19:49:45 raeburn Exp $ +# $Id: LWPReq.pm,v 1.3 2018/09/20 14:17:01 raeburn Exp $ # # The LearningOnline Network with CAPA # @@ -40,7 +40,7 @@ use LWP::UserAgent::DNS::Hosts(); use Apache::lonnet; sub makerequest { - my ($remotehostid,$request,$content,$perlvar,$timeout,$verifycert,$use_lc_ca,$debug) = @_; + my ($remotehostid,$request,$content,$perlvar,$timeout,$verifycert,$use_lc_ca,$islocal,$debug) = @_; unless (ref($perlvar) eq' HASH') { $perlvar = LONCAPA::Configuration::read_conf('loncapa.conf'); } @@ -115,6 +115,9 @@ sub makerequest { if ($use_lc_ca && $remotehostname && $fn) { $ua->requests_redirectable(undef); } + if ($islocal) { + $ua->local_address('127.0.0.1'); + } if ($content ne '') { $response = $ua->request($request,$content); } else { @@ -168,6 +171,14 @@ sub makerequest { if ($use_lc_ca && $remotehostname && $fn) { $ua->requests_redirectable(undef); } + if ($islocal) { + if (LWP::UserAgent->VERSION >= 5.834) { + $ua->local_address('127.0.0.1'); + } else { + local @LWP::Protocol::http::EXTRA_SOCK_OPTS = + (LocalAddr => '127.0.0.1'); + } + } if ($content ne '') { $response = $ua->request($request,$content); } else { @@ -187,6 +198,9 @@ sub makerequest { $response = $ua->request($request); } } + if (($islocal) && (LWP::UserAgent->VERSION < 5.834)) { + local @LWP::Protocol::http::EXTRA_SOCK_OPTS = (); + } } } if ($dns_set) {