diff options
author | Andreas Gohr <andi@splitbrain.org> | 2009-03-13 20:02:47 +0100 |
---|---|---|
committer | Andreas Gohr <andi@splitbrain.org> | 2009-03-13 20:02:47 +0100 |
commit | 758447cfa419f1a11bc022ef8168447992364e52 (patch) | |
tree | 7f10e61b2a085ac08a786bb1d5fa91cd2f4d09b3 /lib/exe/fetch.php | |
parent | af03da1a940f1ada715dcb574ff12a3e23465d99 (diff) | |
download | rpg-758447cfa419f1a11bc022ef8168447992364e52.tar.gz rpg-758447cfa419f1a11bc022ef8168447992364e52.tar.bz2 |
Support for multirange requests for media FS#1630
Ignore-this: 50de569608231b910a62327d2f3af1de
This patch moves all HTTP sending related functions to inc/httputils.php
Handling of range requests was rewritten completely to support mutirange
requests. This should fix problems with Adobe Reader but needs testing.
darcs-hash:20090313190247-7ad00-e6ec1f81acb9f7ac651357dd034c2689aea6868d.gz
Diffstat (limited to 'lib/exe/fetch.php')
-rw-r--r-- | lib/exe/fetch.php | 56 |
1 files changed, 2 insertions, 54 deletions
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 |