--- loncom/homework/daxeopen.pm 2015/12/03 20:40:27 1.1 +++ loncom/homework/daxeopen.pm 2015/12/10 16:26:43 1.2 @@ -1,7 +1,7 @@ # The LearningOnline Network # Opening converted problems and directory listings for Daxe # -# $Id: daxeopen.pm,v 1.1 2015/12/03 20:40:27 damieng Exp $ +# $Id: daxeopen.pm,v 1.2 2015/12/10 16:26:43 damieng Exp $ # # Copyright Michigan State University Board of Trustees # @@ -53,7 +53,8 @@ sub handler { return convert_problem($uri, $request); } else { # Apache should send other files directly - return HTTP_NOT_ACCEPTABLE; + $request->status(406); + return OK; } } @@ -63,7 +64,8 @@ sub convert_problem { my $file = &Apache::lonnet::filelocation('', $uri); &Apache::lonnet::repcopy($file); if (! -e $file) { - return HTTP_NOT_FOUND; + $request->status(404); + return OK; } try { my $warnings = 0; # no warning printed @@ -74,12 +76,10 @@ sub convert_problem { $request->print($text); return OK; } catch { - die "convert failed for $file: $_"; - #$request->print(''."\n"); - #$request->print("\n"); - #$request->print("convert failed for $file: $_"); - #$request->print("\n"); - #return OK; + $request->content_type('text/plain'); + $request->print("convert failed for $file: $_"); + $request->status(406); + return OK; }; } @@ -87,7 +87,8 @@ sub directory_listing { my ($uri, $request) = @_; my $dirpath = &Apache::lonnet::filelocation('', $uri); if (! -e $dirpath) { - return HTTP_NOT_FOUND; + $request->status(404); + return OK; } $dirpath =~ s/\/$//; opendir my $dir, $dirpath or die "Cannot open directory: $dirpath"; @@ -125,26 +126,5 @@ sub directory_listing { return OK; } -# NOTE: binaries should be sent directly be Apache -# sub send_binary { -# my ($request, $filepath) = @_; -# -# $buffer = ''; -# if (!open(FILE, "<", $filepath)) { -# return HTTP_NOT_FOUND; -# } -# binmode(FILE); -# -# # Read file in 32K blocks -# while ((read(FILE, $buffer, 32768)) != 0) { -# $request->print($buffer); -# } -# -# if (!close(FILE)) { -# &Apache::lonnet::logthis("Error closing the file $filepath"); -# } -# return OK; -# } - 1; __END__