From e7a60e27a982c2207097f3a4b88dfbfbaa3f7a6b Mon Sep 17 00:00:00 2001 From: jknockaert Date: Mon, 28 Apr 2014 21:03:19 +0200 Subject: [PATCH] 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. --- lib/download/range.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/download/range.php b/lib/download/range.php index 5aabb2ac..37f17e97 100644 --- a/lib/download/range.php +++ b/lib/download/range.php @@ -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);