fixing http range requests

Range support is broken. The test isset always returns true because the
explode function will return empty strings if nothin is specified. As a
result if parts[0] is an empty string no start is set; same for the
endpoint. This is fixed here. Furthermore if the start is not
specified, the range must be applied to the end of the file as
specified in the the http 1.1 standard. Finally I added brackets to
avoid malformed headers.
pull/1/head
jknockaert 10 years ago
parent f462ab5a7d
commit e7a60e27a9

@ -48,8 +48,13 @@ class Download_Range extends \OCA\Documents\Download {
foreach ($ranges as $range){
$parts = explode('-', $range);
$start = isset($parts[0]) ? $parts[0] : 0;
$end = isset($parts[1]) ? $parts[1] : $size - 1;
if ($parts[0]==='' && $parts[1]=='') {$this->sendNotSatisfiable();}
if ($parts[0]==='') {
$start = $size - $parts[1];
$end = $size - 1;}
else {
$start = $parts[0];
$end = ($parts[1]==='') ? $size - 1 : $parts[1];}
if ($start > $end){
$this->sendNotSatisfiable();
@ -59,7 +64,7 @@ class Download_Range extends \OCA\Documents\Download {
$md5Sum = md5($buffer);
// send the headers and data
header("Content-Length: " . $end - $start);
header("Content-Length: " . ($end - $start));
header("Content-md5: " . $md5Sum);
header("Accept-Ranges: bytes");
header('Content-Range: bytes ' . $start . '-' . ($end) . '/' . $size);

Loading…
Cancel
Save