diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/exe/css.php | 1 | ||||
-rw-r--r-- | lib/exe/fetch.php | 56 | ||||
-rw-r--r-- | lib/exe/js.php | 1 |
3 files changed, 4 insertions, 54 deletions
diff --git a/lib/exe/css.php b/lib/exe/css.php index 7fa56f4cc..2517db38d 100644 --- a/lib/exe/css.php +++ b/lib/exe/css.php @@ -11,6 +11,7 @@ if(!defined('NOSESSION')) define('NOSESSION',true); // we do not use a session o if(!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT',1); // we gzip ourself here require_once(DOKU_INC.'inc/init.php'); require_once(DOKU_INC.'inc/pageutils.php'); +require_once(DOKU_INC.'inc/httputils.php'); require_once(DOKU_INC.'inc/io.php'); require_once(DOKU_INC.'inc/confutils.php'); diff --git a/lib/exe/fetch.php b/lib/exe/fetch.php index ddfff4b4e..728b0b448 100644 --- a/lib/exe/fetch.php +++ b/lib/exe/fetch.php @@ -12,12 +12,12 @@ require_once(DOKU_INC.'inc/common.php'); require_once(DOKU_INC.'inc/media.php'); require_once(DOKU_INC.'inc/pageutils.php'); + require_once(DOKU_INC.'inc/httputils.php'); require_once(DOKU_INC.'inc/confutils.php'); require_once(DOKU_INC.'inc/auth.php'); //close sesseion session_write_close(); - if(!defined('CHUNK_SIZE')) define('CHUNK_SIZE',16*1024); $mimetypes = getMimeTypes(); @@ -139,24 +139,10 @@ function sendFile($file,$mime,$dl,$cache){ //use x-sendfile header to pass the delivery to compatible webservers if (http_sendfile($file)) exit; - //support download continueing - header('Accept-Ranges: bytes'); - list($start,$len) = http_rangeRequest(filesize($file)); - // send file contents $fp = @fopen($file,"rb"); if($fp){ - fseek($fp,$start); //seek to start of range - - $chunk = ($len > CHUNK_SIZE) ? CHUNK_SIZE : $len; - while (!feof($fp) && $chunk > 0) { - @set_time_limit(30); // large files can take a lot of time - print fread($fp, $chunk); - flush(); - $len -= $chunk; - $chunk = ($len > CHUNK_SIZE) ? CHUNK_SIZE : $len; - } - fclose($fp); + http_rangeRequest($fp,filesize($file),$mime); }else{ header("HTTP/1.0 500 Internal Server Error"); print "Could not read $file - bad permissions?"; @@ -164,44 +150,6 @@ function sendFile($file,$mime,$dl,$cache){ } /** - * Checks and sets headers to handle range requets - * - * @author Andreas Gohr <andi@splitbrain.org> - * @returns array The start byte and the amount of bytes to send - */ -function http_rangeRequest($size){ - if(!isset($_SERVER['HTTP_RANGE'])){ - // no range requested - send the whole file - header("Content-Length: $size"); - return array(0,$size); - } - - $t = explode('=', $_SERVER['HTTP_RANGE']); - if (!$t[0]=='bytes') { - // we only understand byte ranges - send the whole file - header("Content-Length: $size"); - return array(0,$size); - } - - $r = explode('-', $t[1]); - $start = (int)$r[0]; - $end = (int)$r[1]; - if (!$end) $end = $size - 1; - if ($start > $end || $start > $size || $end > $size){ - header('HTTP/1.1 416 Requested Range Not Satisfiable'); - print 'Bad Range Request!'; - exit; - } - - $tot = $end - $start + 1; - header('HTTP/1.1 206 Partial Content'); - header("Content-Range: bytes {$start}-{$end}/{$size}"); - header("Content-Length: $tot"); - - return array($start,$tot); -} - -/** * Returns the wanted cachetime in seconds * * Resolves named constants diff --git a/lib/exe/js.php b/lib/exe/js.php index 7746edcd9..7ba777928 100644 --- a/lib/exe/js.php +++ b/lib/exe/js.php @@ -12,6 +12,7 @@ if(!defined('NL')) define('NL',"\n"); if(!defined('DOKU_DISABLE_GZIP_OUTPUT')) define('DOKU_DISABLE_GZIP_OUTPUT',1); // we gzip ourself here require_once(DOKU_INC.'inc/init.php'); require_once(DOKU_INC.'inc/pageutils.php'); +require_once(DOKU_INC.'inc/httputils.php'); require_once(DOKU_INC.'inc/io.php'); require_once(DOKU_INC.'inc/JSON.php'); |