--- loncom/lonnet/perl/lonnet.pm 2008/04/04 16:58:44 1.941.2.2 +++ loncom/lonnet/perl/lonnet.pm 2008/02/21 10:04:35 1.942 @@ -1,7 +1,7 @@ # The LearningOnline Network # TCP networking package # -# $Id: lonnet.pm,v 1.941.2.2 2008/04/04 16:58:44 raeburn Exp $ +# $Id: lonnet.pm,v 1.942 2008/02/21 10:04:35 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -1631,21 +1631,12 @@ sub ssi_body { if (! exists($form{'LONCAPA_INTERNAL_no_discussion'})) { $form{'LONCAPA_INTERNAL_no_discussion'}='true'; } - my $output=''; - my $response; - if ($filelink=~/^http\:/) { - ($output,$response)=&externalssi($filelink); - } else { - ($output,$response)=&ssi($filelink,%form); - } + my $output=($filelink=~/^http\:/?&externalssi($filelink): + &ssi($filelink,%form)); $output=~s|//(\s*)?\s||gs; $output=~s/^.*?\]*\>//si; $output=~s/\<\/body\s*\>.*?$//si; - if (wantarray) { - return ($output, $response); - } else { - return $output; - } + return $output; } # --------------------------------------------------------- Server Side Include @@ -1665,14 +1656,18 @@ sub absolute_url { # fn Possibly encrypted resource name/id. # form Hash that describes how the rendering should be done # and other things. -# Returns: -# Scalar context: The content of the response. -# Array context: 2 element list of the content and the full response object. +# r Optional reference that will be given the response. +# This is mostly provided so that the caller can implement +# error detection, recovery and retry policies. # +# Returns: +# The content of the response. sub ssi { - my ($fn,%form)=@_; + my ($fn,%form, $r)=@_; + my $ua=new LWP::UserAgent; + my $request; $form{'no_update_last_known'}=1; @@ -1687,11 +1682,11 @@ sub ssi { $request->header(Cookie => $ENV{'HTTP_COOKIE'}); my $response=$ua->request($request); - if (wantarray) { - return ($response->content, $response); - } else { - return $response->content; + if ($r) { + $$r = $response; } + + return $response->content; } sub externalssi { @@ -1699,11 +1694,7 @@ sub externalssi { my $ua=new LWP::UserAgent; my $request=new HTTP::Request('GET',$url); my $response=$ua->request($request); - if (wantarray) { - return ($response->content, $response); - } else { - return $response->content; - } + return $response->content; } # -------------------------------- Allow a /uploaded/ URI to be vouched for