From 80032ec30130d0c941cdf6a2217406a7ac2d3c86 Mon Sep 17 00:00:00 2001 From: dratini0 Date: Wed, 11 Feb 2015 21:14:58 +0100 Subject: [PATCH 1/5] Revert "removed a little duplication" This reverts commit 31970ee7409ff2ed303b728ea4fd6f8d10302649. --- lib/private/files.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/private/files.php b/lib/private/files.php index 496ba1baff..d42ab3d185 100644 --- a/lib/private/files.php +++ b/lib/private/files.php @@ -161,11 +161,12 @@ class OC_Files { * @param false|string $filename */ private static function addSendfileHeader($filename) { - $filename = \OC\Files\Filesystem::getLocalFile($filename); if (isset($_SERVER['MOD_X_SENDFILE_ENABLED'])) { + $filename = \OC\Files\Filesystem::getLocalFile($filename); header("X-Sendfile: " . $filename); } if (isset($_SERVER['MOD_X_SENDFILE2_ENABLED'])) { + $filename = \OC\Files\Filesystem::getLocalFile($filename); if (isset($_SERVER['HTTP_RANGE']) && preg_match("/^bytes=([0-9]+)-([0-9]*)$/", $_SERVER['HTTP_RANGE'], $range)) { $filelength = filesize($filename); @@ -181,6 +182,7 @@ class OC_Files { } if (isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])) { + $filename = \OC\Files\Filesystem::getLocalFile($filename); header("X-Accel-Redirect: " . $filename); } } From b1594ad1dfe505b3d0daf0a23993df8d8ee3d502 Mon Sep 17 00:00:00 2001 From: dratini0 Date: Wed, 11 Feb 2015 21:15:13 +0100 Subject: [PATCH 2/5] Revert "Fix: X-Accel-Redirect did not support custom data dir and local mounts" This reverts commit f2075f803fc59918cc20071cf174d6b5f81f5eed. --- lib/private/files.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/files.php b/lib/private/files.php index d42ab3d185..98f3c52d6c 100644 --- a/lib/private/files.php +++ b/lib/private/files.php @@ -182,7 +182,7 @@ class OC_Files { } if (isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])) { - $filename = \OC\Files\Filesystem::getLocalFile($filename); + $filename = \OC::$WEBROOT . '/data' . \OC\Files\Filesystem::getRoot() . $filename; header("X-Accel-Redirect: " . $filename); } } From 10e13b172afeb9d25f640415920fa9fab16d2375 Mon Sep 17 00:00:00 2001 From: dratini0 Date: Wed, 11 Feb 2015 22:10:06 +0100 Subject: [PATCH 3/5] Extending the X-accel redirect functionality with a more scalable approach. --- lib/private/files.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/private/files.php b/lib/private/files.php index 98f3c52d6c..3a2e291630 100644 --- a/lib/private/files.php +++ b/lib/private/files.php @@ -182,7 +182,16 @@ class OC_Files { } if (isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])) { - $filename = \OC::$WEBROOT . '/data' . \OC\Files\Filesystem::getRoot() . $filename; + if (isset($_SERVER['MOD_X_ACCEL_REDIRECT_PREFIX'])) { + $prefix = $_SERVER['MOD_X_ACCEL_REDIRECT_PREFIX']; + // nginx is picky about double slashes + while($prefix[strlen($prefix) - 1] === '/'){ + $prefix = substr($prefix, 0, -1); + } + $filename = $prefix . \OC\Files\Filesystem::getLocalFile($filename); + } else { + $filename = \OC::$WEBROOT . '/data' . \OC\Files\Filesystem::getRoot() . $filename; + } header("X-Accel-Redirect: " . $filename); } } From c432b52c748479b08a4b80678e3bec1f387ecf76 Mon Sep 17 00:00:00 2001 From: dratini0 Date: Mon, 23 Mar 2015 16:12:03 +0100 Subject: [PATCH 4/5] Changed the disputed while loop to a single if. --- lib/private/files.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/private/files.php b/lib/private/files.php index 3a2e291630..6d165bcc70 100644 --- a/lib/private/files.php +++ b/lib/private/files.php @@ -184,8 +184,8 @@ class OC_Files { if (isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])) { if (isset($_SERVER['MOD_X_ACCEL_REDIRECT_PREFIX'])) { $prefix = $_SERVER['MOD_X_ACCEL_REDIRECT_PREFIX']; - // nginx is picky about double slashes - while($prefix[strlen($prefix) - 1] === '/'){ + // nginx is picky about double slashes when matching locations + if($prefix[strlen($prefix) - 1] === '/'){ $prefix = substr($prefix, 0, -1); } $filename = $prefix . \OC\Files\Filesystem::getLocalFile($filename); From d4e5ef4f38a0b3c48537bc7e27a14563e76b6391 Mon Sep 17 00:00:00 2001 From: dratini0 Date: Mon, 23 Mar 2015 17:51:12 +0100 Subject: [PATCH 5/5] Removed simplified X-accel-redirect even further --- lib/private/files.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/private/files.php b/lib/private/files.php index 6d165bcc70..b7df99c7d7 100644 --- a/lib/private/files.php +++ b/lib/private/files.php @@ -183,12 +183,7 @@ class OC_Files { if (isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED'])) { if (isset($_SERVER['MOD_X_ACCEL_REDIRECT_PREFIX'])) { - $prefix = $_SERVER['MOD_X_ACCEL_REDIRECT_PREFIX']; - // nginx is picky about double slashes when matching locations - if($prefix[strlen($prefix) - 1] === '/'){ - $prefix = substr($prefix, 0, -1); - } - $filename = $prefix . \OC\Files\Filesystem::getLocalFile($filename); + $filename = $_SERVER['MOD_X_ACCEL_REDIRECT_PREFIX'] . \OC\Files\Filesystem::getLocalFile($filename); } else { $filename = \OC::$WEBROOT . '/data' . \OC\Files\Filesystem::getRoot() . $filename; }