aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/response.php
diff options
context:
space:
mode:
authorAndreas Fischer <bantu@owncloud.com>2015-03-26 16:24:15 +0100
committerAndreas Fischer <bantu@owncloud.com>2015-03-26 16:37:38 +0100
commit0f58315543a6f3b87d4376cea493c13645687bc2 (patch)
treef273acf222a799270a614ae2eab28f2a148f6b9e /lib/private/response.php
parent0d786c381b8d4656e6bbcb5ef2b33e718ea639eb (diff)
downloadnextcloud-server-0f58315543a6f3b87d4376cea493c13645687bc2.tar.gz
nextcloud-server-0f58315543a6f3b87d4376cea493c13645687bc2.zip
Add OC_Response::setContentLengthHeader() for Apache PHP SAPI workaround.
Do not send Content-Length headers with a value larger than PHP_INT_MAX (2147483647) on Apache PHP SAPI 32-bit. PHP will eat them and send 2147483647 instead. When X-Sendfile is enabled, Apache will send a correct Content-Length header, even for files larger than 2147483647 bytes. When X-Sendfile is not enabled, ownCloud will not send a Content-Length header. This prevents progress bars from working, but allows the actual transfer to work properly.
Diffstat (limited to 'lib/private/response.php')
-rw-r--r--lib/private/response.php23
1 files changed, 22 insertions, 1 deletions
diff --git a/lib/private/response.php b/lib/private/response.php
index 2bec5e3decd..7cd362ecdf3 100644
--- a/lib/private/response.php
+++ b/lib/private/response.php
@@ -172,6 +172,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
*/
@@ -181,7 +202,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 {