mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +02:00
MDL-48023 Files API: Theme files must be cache-able by shared proxies.
The profile image AKA user icon will be cache-able by shared proxies too, under its specific accessibility constraints/conditions.
This commit is contained in:
parent
c106341098
commit
bb8ed60a3c
4 changed files with 37 additions and 9 deletions
|
@ -2288,12 +2288,13 @@ function send_file($path, $filename, $lifetime = null , $filter=0, $pathisstring
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($lifetime > 0) {
|
if ($lifetime > 0) {
|
||||||
$private = '';
|
$cacheability = ' public,';
|
||||||
if (isloggedin() and !isguestuser()) {
|
if (isloggedin() and !isguestuser()) {
|
||||||
$private = ' private,';
|
// By default, under the conditions above, this file must be cache-able only by browsers.
|
||||||
|
$cacheability = ' private,';
|
||||||
}
|
}
|
||||||
$nobyteserving = false;
|
$nobyteserving = false;
|
||||||
header('Cache-Control:'.$private.' max-age='.$lifetime.', no-transform');
|
header('Cache-Control:'.$cacheability.' max-age='.$lifetime.', no-transform');
|
||||||
header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .' GMT');
|
header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .' GMT');
|
||||||
header('Pragma: ');
|
header('Pragma: ');
|
||||||
|
|
||||||
|
@ -2366,7 +2367,10 @@ function send_file($path, $filename, $lifetime = null , $filter=0, $pathisstring
|
||||||
* (bool) dontdie - return control to caller afterwards. this is not recommended and only used for cleanup tasks.
|
* (bool) dontdie - return control to caller afterwards. this is not recommended and only used for cleanup tasks.
|
||||||
* if this is passed as true, ignore_user_abort is called. if you don't want your processing to continue on cancel,
|
* if this is passed as true, ignore_user_abort is called. if you don't want your processing to continue on cancel,
|
||||||
* you must detect this case when control is returned using connection_aborted. Please not that session is closed
|
* you must detect this case when control is returned using connection_aborted. Please not that session is closed
|
||||||
* and should not be reopened.
|
* and should not be reopened
|
||||||
|
* (string|null) cacheability - force the cacheability setting of the HTTP response, "private" or "public",
|
||||||
|
* when $lifetime is greater than 0. Cacheability defaults to "private" when logged in as other than guest; otherwise,
|
||||||
|
* defaults to "public".
|
||||||
*
|
*
|
||||||
* @category files
|
* @category files
|
||||||
* @param stored_file $stored_file local file object
|
* @param stored_file $stored_file local file object
|
||||||
|
@ -2463,11 +2467,17 @@ function send_stored_file($stored_file, $lifetime=null, $filter=0, $forcedownloa
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($lifetime > 0) {
|
if ($lifetime > 0) {
|
||||||
$private = '';
|
$cacheability = ' public,';
|
||||||
if (isloggedin() and !isguestuser()) {
|
if (!empty($options['cacheability']) && ($options['cacheability'] === 'public')) {
|
||||||
$private = ' private,';
|
// This file must be cache-able by both browsers and proxies.
|
||||||
|
$cacheability = ' public,';
|
||||||
|
} else if (!empty($options['cacheability']) && ($options['cacheability'] === 'private')) {
|
||||||
|
// This file must be cache-able only by browsers.
|
||||||
|
$cacheability = ' private,';
|
||||||
|
} else if (isloggedin() and !isguestuser()) {
|
||||||
|
$cacheability = ' private,';
|
||||||
}
|
}
|
||||||
header('Cache-Control:'.$private.' max-age='.$lifetime.', no-transform');
|
header('Cache-Control:'.$cacheability.' max-age='.$lifetime.', no-transform');
|
||||||
header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .' GMT');
|
header('Expires: '. gmdate('D, d M Y H:i:s', time() + $lifetime) .' GMT');
|
||||||
header('Pragma: ');
|
header('Pragma: ');
|
||||||
|
|
||||||
|
@ -4177,7 +4187,13 @@ function file_pluginfile($relativepath, $forcedownload, $preview = null) {
|
||||||
send_file($imagefile, basename($imagefile), 60*60*24*14);
|
send_file($imagefile, basename($imagefile), 60*60*24*14);
|
||||||
}
|
}
|
||||||
|
|
||||||
send_stored_file($file, 60*60*24*365, 0, false, array('preview' => $preview)); // enable long caching, there are many images on each page
|
$options = array('preview' => $preview);
|
||||||
|
if (empty($CFG->forcelogin) && empty($CFG->forceloginforprofileimage)) {
|
||||||
|
// Profile images should be cache-able by both browsers and proxies according
|
||||||
|
// to $CFG->forcelogin and $CFG->forceloginforprofileimage.
|
||||||
|
$options['cacheability'] = 'public';
|
||||||
|
}
|
||||||
|
send_stored_file($file, 60*60*24*365, 0, false, $options); // enable long caching, there are many images on each page
|
||||||
|
|
||||||
} else if ($filearea === 'private' and $context->contextlevel == CONTEXT_USER) {
|
} else if ($filearea === 'private' and $context->contextlevel == CONTEXT_USER) {
|
||||||
require_login();
|
require_login();
|
||||||
|
|
|
@ -1475,6 +1475,10 @@ class theme_config {
|
||||||
$lifetime = 0;
|
$lifetime = 0;
|
||||||
} else {
|
} else {
|
||||||
$lifetime = 60*60*24*60;
|
$lifetime = 60*60*24*60;
|
||||||
|
// By default, theme files must be cache-able by both browsers and proxies.
|
||||||
|
if (!array_key_exists('cacheability', $options)) {
|
||||||
|
$options['cacheability'] = 'public';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$fs = get_file_storage();
|
$fs = get_file_storage();
|
||||||
|
|
|
@ -88,6 +88,10 @@ function theme_clean_set_logo($css, $logo) {
|
||||||
function theme_clean_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
|
function theme_clean_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
|
||||||
if ($context->contextlevel == CONTEXT_SYSTEM and $filearea === 'logo') {
|
if ($context->contextlevel == CONTEXT_SYSTEM and $filearea === 'logo') {
|
||||||
$theme = theme_config::load('clean');
|
$theme = theme_config::load('clean');
|
||||||
|
// By default, theme files must be cache-able by both browsers and proxies.
|
||||||
|
if (!array_key_exists('cacheability', $options)) {
|
||||||
|
$options['cacheability'] = 'public';
|
||||||
|
}
|
||||||
return $theme->setting_file_serve('logo', $args, $forcedownload, $options);
|
return $theme->setting_file_serve('logo', $args, $forcedownload, $options);
|
||||||
} else {
|
} else {
|
||||||
send_file_not_found();
|
send_file_not_found();
|
||||||
|
|
|
@ -149,6 +149,10 @@ function theme_more_set_logo($css, $logo) {
|
||||||
function theme_more_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
|
function theme_more_pluginfile($course, $cm, $context, $filearea, $args, $forcedownload, array $options = array()) {
|
||||||
if ($context->contextlevel == CONTEXT_SYSTEM && ($filearea === 'logo' || $filearea === 'backgroundimage')) {
|
if ($context->contextlevel == CONTEXT_SYSTEM && ($filearea === 'logo' || $filearea === 'backgroundimage')) {
|
||||||
$theme = theme_config::load('more');
|
$theme = theme_config::load('more');
|
||||||
|
// By default, theme files must be cache-able by both browsers and proxies.
|
||||||
|
if (!array_key_exists('cacheability', $options)) {
|
||||||
|
$options['cacheability'] = 'public';
|
||||||
|
}
|
||||||
return $theme->setting_file_serve($filearea, $args, $forcedownload, $options);
|
return $theme->setting_file_serve($filearea, $args, $forcedownload, $options);
|
||||||
} else {
|
} else {
|
||||||
send_file_not_found();
|
send_file_not_found();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue