MDL-47545 web services: Allow cross origin requests for file downloads
This commit is contained in:
@@ -1953,6 +1953,13 @@ function file_mimetype_in_typegroup($mimetype, $groups) {
|
||||
*/
|
||||
function send_file_not_found() {
|
||||
global $CFG, $COURSE;
|
||||
|
||||
// Allow cross-origin requests only for Web Services.
|
||||
// This allow to receive requests done by Web Workers or webapps in different domains.
|
||||
if (WS_SERVER) {
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
}
|
||||
|
||||
send_header_404();
|
||||
print_error('filenotfound', 'error', $CFG->wwwroot.'/course/view.php?id='.$COURSE->id); //this is not displayed on IIS??
|
||||
}
|
||||
@@ -2476,6 +2483,12 @@ function send_stored_file($stored_file, $lifetime=null, $filter=0, $forcedownloa
|
||||
}
|
||||
}
|
||||
|
||||
// Allow cross-origin requests only for Web Services.
|
||||
// This allow to receive requests done by Web Workers or webapps in different domains.
|
||||
if (WS_SERVER) {
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
}
|
||||
|
||||
if (empty($filter)) {
|
||||
// send the contents
|
||||
readfile_accel($stored_file, $mimetype, !$dontdie);
|
||||
|
||||
@@ -184,6 +184,8 @@ class webservice_rest_server extends webservice_base_server {
|
||||
header('Expires: '. gmdate('D, d M Y H:i:s', 0) .' GMT');
|
||||
header('Pragma: no-cache');
|
||||
header('Accept-Ranges: none');
|
||||
// Allow cross-origin requests only for Web Services.
|
||||
// This allow to receive requests done by Web Workers or webapps in different domains.
|
||||
header('Access-Control-Allow-Origin: *');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user