aboutsummaryrefslogtreecommitdiffstats
path: root/lib/files.php
diff options
context:
space:
mode:
authormvn23 <schopdiedwaas@gmail.com>2013-06-19 15:36:48 +0200
committermvn23 <schopdiedwaas@gmail.com>2013-06-19 15:36:48 +0200
commit46f97f4c389572eb1edac30d8cfa7086835c58fb (patch)
tree63a075d65ea7b24c20c71c6728ab42727a90aebe /lib/files.php
parentcb41b88520498ca2325aedd180c3fe29474c83bf (diff)
downloadnextcloud-server-46f97f4c389572eb1edac30d8cfa7086835c58fb.tar.gz
nextcloud-server-46f97f4c389572eb1edac30d8cfa7086835c58fb.zip
Implement X-Sendfile2 for resume support in LigHTTPd
LigHTTPd does not support HTTP Range headers with the X-Sendfile header in the way Apache does. Instead, it needs to be handled in the backend. This commit does exactly that, using the X-Sendfile2 header to send ranges of files. To accomplish this without breaking web servers that don't support X-Sendfile2, a new variable MOD_X_SENDFILE2_ENABLED was introduced to separate this method from X-Sendfile and X-Accel-Redirect.
Diffstat (limited to 'lib/files.php')
-rw-r--r--lib/files.php14
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/files.php b/lib/files.php
index abb1617c25e..5dd65e85a43 100644
--- a/lib/files.php
+++ b/lib/files.php
@@ -45,7 +45,7 @@ class OC_Files {
*/
public static function get($dir, $files, $only_header = false) {
$xsendfile = false;
- if (isset($_SERVER['MOD_X_SENDFILE_ENABLED']) ||
+ if (isset($_SERVER['MOD_X_SENDFILE_ENABLED']) || isset($_SERVER['MOD_X_SENDFILE2_ENABLED']) ||
isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])) {
$xsendfile = true;
}
@@ -170,6 +170,18 @@ class OC_Files {
private static function addSendfileHeader($filename) {
if (isset($_SERVER['MOD_X_SENDFILE_ENABLED'])) {
header("X-Sendfile: " . $filename);
+ }
+ if (isset($_SERVER['MOD_X_SENDFILE2_ENABLED'])) {
+ if (isset($_SERVER['HTTP_RANGE']) && preg_match('/\Abytes=(?P<start>[0-9]+)-(?P<end>[0-9]*)\z/', $_SERVER['HTTP_RANGE'], $range)) {
+ if ($range['end'] == "") {
+ $range['end'] = filesize($filename) - 1;
+ }
+ header("Content-Range: bytes " . $range['start'] . "-" . $range['end'] . "/" . filesize($filename));
+ header("HTTP/1.1 206 Partial content");
+ header("X-Sendfile2: " . str_replace(",", "%2c", rawurlencode($filename)) . " " . $range['start'] . "-" . $range['end']);
+ } else {
+ header("X-Sendfile: " . $filename);
+ }
}
if (isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])) {
header("X-Accel-Redirect: " . $filename);