--- loncom/interface/loncommon.pm 2019/05/02 02:12:18 1.1328 +++ loncom/interface/loncommon.pm 2019/05/02 23:09:38 1.1329 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # a pile of common routines # -# $Id: loncommon.pm,v 1.1328 2019/05/02 02:12:18 raeburn Exp $ +# $Id: loncommon.pm,v 1.1329 2019/05/02 23:09:38 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -18193,7 +18193,26 @@ sub shorten_symbs { } sub is_nonframeable { - my ($url,$absolute,$hostname,$ip) = @_; + my ($url,$absolute,$hostname,$ip,$nocache) = @_; + my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i); + return if (($remprotocol eq '') || ($remhost eq '')); + + $remprotocol = lc($remprotocol); + $remhost = lc($remhost); + my $remport = 80; + if ($remprotocol eq 'https') { + $remport = 443; + } + my ($result,$cached) = &Apache::lonnet::is_cached_new('exturlnoiframe',$remhost.':'.$remport); + if ($cached) { + unless ($nocache) { + if ($result) { + return 1; + } else { + return 0; + } + } + } my $uselink; my $request = new HTTP::Request('HEAD',$url); my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',5); @@ -18203,8 +18222,7 @@ sub is_nonframeable { $secpolicy =~ s/^\s+|\s+$//g; $xframeop =~ s/^\s+|\s+$//g; if (($secpolicy ne '') || ($xframeop ne '')) { - my ($remotehost) = ($url =~ m{^(https?\://[^/?#]+)}); - $remotehost = lc($remotehost); + my $remotehost = $remprotocol.'://'.$remhost; my ($origin,$protocol,$port); if ($ENV{'SERVER_PORT'} =~/^\d+$/) { $port = $ENV{'SERVER_PORT'}; @@ -18302,10 +18320,29 @@ sub is_nonframeable { } } } + if ($nocache) { + if ($cached) { + my $devalidate; + if ($uselink && !$result) { + $devalidate = 1; + } elsif (!$uselink && $result) { + $devalidate = 1; + } + if ($devalidate) { + &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport); + } + } + } else { + if ($uselink) { + $result = 1; + } else { + $result = 0; + } + &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600); + } return $uselink; } - 1; __END__;