Browse Source

Merge pull request #15229 from owncloud/response-setContentLengthHeader

Add OC_Response::setContentLengthHeader() for Apache PHP SAPI workaround...
remotes/origin/poc-doctrine-migrations
Thomas Müller 11 years ago
parent
commit
3bf269e565
  1. 2
      apps/files/download.php
  2. 2
      apps/files_versions/download.php
  3. 2
      lib/private/files.php
  4. 23
      lib/private/response.php
  5. 8
      lib/public/response.php

2
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 );

2
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();

2
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);
}
}
}

23
lib/private/response.php

@ -190,6 +190,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 {

8
lib/public/response.php

@ -67,6 +67,14 @@ class Response {
\OC_Response::setContentDispositionHeader( $filename, $type );
}
/**
* 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

Loading…
Cancel
Save