]> source.dussan.org Git - nextcloud-server.git/commitdiff
Implemented X-Sendfile support
authorValerio Ponte <valerio.ponte@gmail.com>
Fri, 12 Oct 2012 20:07:00 +0000 (22:07 +0200)
committerValerio Ponte <valerio.ponte@gmail.com>
Wed, 14 Nov 2012 19:10:20 +0000 (20:10 +0100)
lib/filesystemview.php

index 0229213ebcb1a9b7c6dc0eb4f9c33f0290eb94f5..a0ff527cd91aedaaeba83c0a94ef4949a19e8fc0 100644 (file)
@@ -195,6 +195,7 @@ class OC_FilesystemView {
                return $this->basicOperation('filesize', $path);
        }
        public function readfile($path) {
+               $this->addSendfileHeaders($path);
                @ob_end_clean();
                $handle=$this->fopen($path, 'rb');
                if ($handle) {
@@ -208,6 +209,19 @@ class OC_FilesystemView {
                }
                return false;
        }
+       /* This adds the proper header to let the web server handle
+       * the file transfer, if it's configured through the right
+       * environment variable
+       */
+       private function addSendfileHeaders($path) {
+               $storage = $this->getStorage($path);
+               if ($storage instanceof OC_Filestorage_Local) {
+                       if (isset($_SERVER['MOD_X_ACCEL_REDIRECT_ENABLED']))
+                               header("X-Accel-Redirect: " . $this->getLocalFile($path));
+                       if (isset($_SERVER['MOD_X_SENDFILE_ENABLED']))
+                               header("X-Sendfile: " . $this->getLocalFile($path));
+               }
+       }
        /**
        * @deprecated Replaced by isReadable() as part of CRUDS
        */