--- loncom/LWPReq.pm 2016/07/25 19:49:45 1.2 +++ loncom/LWPReq.pm 2018/12/22 17:52:39 1.5 @@ -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.5 2018/12/22 17:52:39 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,15 @@ 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 { + require LWP::Protocol::http; + local @LWP::Protocol::http::EXTRA_SOCK_OPTS = + (LocalAddr => '127.0.0.1'); + } + } if ($content ne '') { $response = $ua->request($request,$content); } else { @@ -187,8 +199,14 @@ sub makerequest { $response = $ua->request($request); } } + if (($islocal) && (LWP::UserAgent->VERSION < 5.834)) { + local @LWP::Protocol::http::EXTRA_SOCK_OPTS = (); + } } } + if ($debug) { + $IO::Socket::SSL::DEBUG=0; + } if ($dns_set) { $dns_set = &unsetdns(); }