diff options
author | Morris Jobke <hey@morrisjobke.de> | 2015-05-20 11:17:24 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2015-05-20 11:17:24 +0200 |
commit | 3bc312ef9a5936b13492194565d5fddc1f920e49 (patch) | |
tree | 603b60e3c8140395ab7cb3491776aabc29ea9c81 /lib | |
parent | 68b2a85ed01bed3c9d7cb9843e3b62f6ecbfaf31 (diff) | |
parent | 94ada409bbc9a0151a952b89bcfdebe32ba6c105 (diff) | |
download | nextcloud-server-3bc312ef9a5936b13492194565d5fddc1f920e49.tar.gz nextcloud-server-3bc312ef9a5936b13492194565d5fddc1f920e49.zip |
Merge pull request #15401 from owncloud/response-setContentLengthHeader-stable8
[stable8] Add OC_Response::setContentLengthHeader() for Apache PHP SAPI workaround.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/files.php | 2 | ||||
-rw-r--r-- | lib/private/response.php | 23 | ||||
-rw-r--r-- | lib/public/response.php | 8 |
3 files changed, 31 insertions, 2 deletions
diff --git a/lib/private/files.php b/lib/private/files.php index b7df99c7d70..be08fd37d60 100644 --- a/lib/private/files.php +++ b/lib/private/files.php @@ -48,7 +48,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 cf18115111a..f49dbc101d8 100644 --- a/lib/private/response.php +++ b/lib/private/response.php @@ -171,6 +171,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 */ @@ -180,7 +201,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 24d3c81d628..c32eb4a05e0 100644 --- a/lib/public/response.php +++ b/lib/public/response.php @@ -64,6 +64,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 */ |