MDL-66493 filelib: readstring_accel should never use xsendfile

This commit is contained in:
Brendan Heywood 2019-09-26 14:48:47 +10:00
parent 9f997f9bd7
commit d6f5fbb720
3 changed files with 9 additions and 16 deletions

View File

@ -53,7 +53,7 @@ if (null !== $logid) {
header("Content-Disposition: attachment; filename=\"{$filename}\"");
}
readstring_accel($log->output, 'text/plain', false);
readstring_accel($log->output, 'text/plain');
exit;
}

View File

@ -2250,10 +2250,10 @@ function readfile_accel($file, $mimetype, $accelerate) {
* Similar to readfile_accel() but designed for strings.
* @param string $string
* @param string $mimetype
* @param bool $accelerate
* @param bool $accelerate Ignored
* @return void
*/
function readstring_accel($string, $mimetype, $accelerate) {
function readstring_accel($string, $mimetype, $accelerate = false) {
global $CFG;
if ($mimetype === 'text/plain') {
@ -2264,14 +2264,6 @@ function readstring_accel($string, $mimetype, $accelerate) {
}
header('Last-Modified: '. gmdate('D, d M Y H:i:s', time()) .' GMT');
header('Accept-Ranges: none');
if ($accelerate and !empty($CFG->xsendfile)) {
$fs = get_file_storage();
if ($fs->xsendfile(sha1($string))) {
return;
}
}
header('Content-Length: '.strlen($string));
echo $string;
}
@ -2320,7 +2312,7 @@ function send_temp_file($path, $filename, $pathisstring=false) {
// send the contents - we can not accelerate this because the file will be deleted asap
if ($pathisstring) {
readstring_accel($path, $mimetype, false);
readstring_accel($path, $mimetype);
} else {
readfile_accel($path, $mimetype, false);
@unlink($path);
@ -2506,7 +2498,7 @@ function send_file($path, $filename, $lifetime = null , $filter=0, $pathisstring
if (empty($filter)) {
// send the contents
if ($pathisstring) {
readstring_accel($path, $mimetype, !$dontdie);
readstring_accel($path, $mimetype);
} else {
readfile_accel($path, $mimetype, !$dontdie);
}
@ -2526,7 +2518,7 @@ function send_file($path, $filename, $lifetime = null , $filter=0, $pathisstring
}
$output = format_text($text, FORMAT_HTML, $options, $COURSE->id);
readstring_accel($output, $mimetype, false);
readstring_accel($output, $mimetype);
} else if (($mimetype == 'text/plain') and ($filter == 1)) {
// only filter text if filter all files is selected
@ -2542,12 +2534,12 @@ function send_file($path, $filename, $lifetime = null , $filter=0, $pathisstring
}
$output = '<pre>'. format_text($text, FORMAT_MOODLE, $options, $COURSE->id) .'</pre>';
readstring_accel($output, $mimetype, false);
readstring_accel($output, $mimetype);
} else {
// send the contents
if ($pathisstring) {
readstring_accel($path, $mimetype, !$dontdie);
readstring_accel($path, $mimetype);
} else {
readfile_accel($path, $mimetype, !$dontdie);
}

View File

@ -68,6 +68,7 @@ validation against and defaults to null (so, no user needed) if not provided.
and should be set to either false or true. Developers will probably want to set this to false.
* The core_enrol_edit_user_enrolment webservice has been deprecated. Please use core_enrol_submit_user_enrolment_form instead.
* \single_button constructor has a new attributes param to add attributes to the button HTML tag.
* Attempting to use xsendfile via the 3rd param of readstring_accel() is now ignored.
=== 3.7 ===