diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-04-03 22:51:36 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2015-04-03 22:51:36 +0200 |
commit | 3bf269e5655d6b54c63ad2336406de73f145935e (patch) | |
tree | ed29895a6ec2e2f44ac081ae1c7fa9d4ec70e1e9 | |
parent | b2b3e1ac946d340b1c5b9ff1af97def6365c4967 (diff) | |
parent | 0f58315543a6f3b87d4376cea493c13645687bc2 (diff) | |
download | nextcloud-server-3bf269e5655d6b54c63ad2336406de73f145935e.tar.gz nextcloud-server-3bf269e5655d6b54c63ad2336406de73f145935e.zip |
Merge pull request #15229 from owncloud/response-setContentLengthHeader
Add OC_Response::setContentLengthHeader() for Apache PHP SAPI workaround...
-rw-r--r-- | apps/files/download.php | 2 | ||||
-rw-r--r-- | apps/files_versions/download.php | 2 | ||||
-rw-r--r-- | lib/private/files.php | 2 | ||||
-rw-r--r-- | lib/private/response.php | 23 | ||||
-rw-r--r-- | lib/public/response.php | 8 |
5 files changed, 33 insertions, 4 deletions
diff --git a/apps/files/download.php b/apps/files/download.php index 1af576051bd..c85051e0f4e 100644 --- a/apps/files/download.php +++ b/apps/files/download.php @@ -43,7 +43,7 @@ $ftype=\OC_Helper::getSecureMimeType(\OC\Files\Filesystem::getMimeType( $filenam header('Content-Type:'.$ftype); OCP\Response::setContentDispositionHeader(basename($filename), 'attachment'); OCP\Response::disableCaching(); -header('Content-Length: '.\OC\Files\Filesystem::filesize($filename)); +OCP\Response::setContentLengthHeader(\OC\Files\Filesystem::filesize($filename)); OC_Util::obEnd(); \OC\Files\Filesystem::readfile( $filename ); diff --git a/apps/files_versions/download.php b/apps/files_versions/download.php index 799d75b5b4a..72018ca68b9 100644 --- a/apps/files_versions/download.php +++ b/apps/files_versions/download.php @@ -39,7 +39,7 @@ $ftype = $view->getMimeType('/'.$uid.'/files/'.$filename); header('Content-Type:'.$ftype); OCP\Response::setContentDispositionHeader(basename($filename), 'attachment'); OCP\Response::disableCaching(); -header('Content-Length: '.$view->filesize($versionName)); +OCP\Response::setContentLengthHeader($view->filesize($versionName)); OC_Util::obEnd(); diff --git a/lib/private/files.php b/lib/private/files.php index 0f48dca9715..d0c1baa0c1e 100644 --- a/lib/private/files.php +++ b/lib/private/files.php @@ -69,7 +69,7 @@ class OC_Files { $filesize = \OC\Files\Filesystem::filesize($filename); header('Content-Type: '.\OC_Helper::getSecureMimeType(\OC\Files\Filesystem::getMimeType($filename))); if ($filesize > -1) { - header("Content-Length: ".$filesize); + OC_Response::setContentLengthHeader($filesize); } } } diff --git a/lib/private/response.php b/lib/private/response.php index ba458cb6afd..018c44d2367 100644 --- a/lib/private/response.php +++ b/lib/private/response.php @@ -191,6 +191,27 @@ class OC_Response { } /** + * Sets the content length header (with possible workarounds) + * @param string|int|float $length Length to be sent + */ + static public function setContentLengthHeader($length) { + if (PHP_INT_SIZE === 4) { + if ($length > PHP_INT_MAX && stripos(PHP_SAPI, 'apache') === 0) { + // Apache PHP SAPI casts Content-Length headers to PHP integers. + // This enforces a limit of PHP_INT_MAX (2147483647 on 32-bit + // platforms). So, if the length is greater than PHP_INT_MAX, + // we just do not send a Content-Length header to prevent + // bodies from being received incompletely. + return; + } + // Convert signed integer or float to unsigned base-10 string. + $lfh = new \OC\LargeFileHelper; + $length = $lfh->formatUnsignedInteger($length); + } + header('Content-Length: '.$length); + } + + /** * Send file as response, checking and setting caching headers * @param string $filepath of file to send */ @@ -200,7 +221,7 @@ class OC_Response { self::setLastModifiedHeader(filemtime($filepath)); self::setETagHeader(md5_file($filepath)); - header('Content-Length: '.filesize($filepath)); + self::setContentLengthHeader(filesize($filepath)); fpassthru($fp); } else { diff --git a/lib/public/response.php b/lib/public/response.php index 2f0922c49ed..d4d32e89ab7 100644 --- a/lib/public/response.php +++ b/lib/public/response.php @@ -68,6 +68,14 @@ class Response { } /** + * Sets the content length header (with possible workarounds) + * @param string|int|float $length Length to be sent + */ + static public function setContentLengthHeader($length) { + \OC_Response::setContentLengthHeader($length); + } + + /** * Disable browser caching * @see enableCaching with cache_time = 0 */ |