Skip to content

Commit

Permalink
Merge branch 'MDL-68342-xsendfile-file' of https://github.com/brendan…
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Apr 28, 2020
2 parents a8eba6e + 5bf5a7a commit b03a633
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/filelib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2169,7 +2169,7 @@ function readfile_accel($file, $mimetype, $accelerate) {
if (is_object($file)) {
$fs = get_file_storage();
if ($fs->supports_xsendfile()) {
if ($fs->xsendfile($file->get_contenthash())) {
if ($fs->xsendfile_file($file)) {
return;
}
}
Expand Down
15 changes: 15 additions & 0 deletions lib/filestorage/file_storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -1821,6 +1821,21 @@ protected function call_before_file_created_plugin_functions($newrecord, $pathna
}
}

/**
* Serve file content using X-Sendfile header.
* Please make sure that all headers are already sent and the all
* access control checks passed.
*
* This alternate method to xsendfile() allows an alternate file system
* to use the full file metadata and avoid extra lookups.
*
* @param stored_file $file The file to send
* @return bool success
*/
public function xsendfile_file(stored_file $file): bool {
return $this->filesystem->xsendfile_file($file);
}

/**
* Serve file content using X-Sendfile header.
* Please make sure that all headers are already sent
Expand Down
15 changes: 15 additions & 0 deletions lib/filestorage/file_system.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,21 @@ protected function get_imageinfo_from_path($path) {
return $image;
}

/**
* Serve file content using X-Sendfile header.
* Please make sure that all headers are already sent and the all
* access control checks passed.
*
* This alternate method to xsendfile() allows an alternate file system
* to use the full file metadata and avoid extra lookups.
*
* @param stored_file $file The file to send
* @return bool success
*/
public function xsendfile_file(stored_file $file): bool {
return $this->xsendfile($file->get_contenthash());
}

/**
* Serve file content using X-Sendfile header.
* Please make sure that all headers are already sent and the all
Expand Down
1 change: 1 addition & 0 deletions lib/upgrade.txt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ information provided here is intended especially for developers.
* External functions can be called without requiring a session lock if they define 'readonlysession' => true in
db/services.php. Note - this also requires $CFG->enable_read_only_sessions to be set to true.
* database_manager::check_database_schema() now checks for missing and extra indexes.
* Implement a more direct xsendfile_file() method for an alternative_file_system_class

=== 3.8 ===
* Add CLI option to notify all cron tasks to stop: admin/cli/cron.php --stop
Expand Down

0 comments on commit b03a633

Please sign in to comment.