fix range header and test

This commit is contained in:
Damodar Lohani 2021-09-13 12:07:27 +05:45
parent 547302c80c
commit cc65339a01
3 changed files with 6 additions and 5 deletions

View file

@ -1069,7 +1069,7 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/download')
list($unit, $range) = explode('=', $rangeHeader);
if($unit == 'bytes' && !empty($range)) {
list($rangeStart, $rangeEnd) = explode('-', $range);
if(strlen($rangeStart) == 0) {
if(strlen($rangeStart) == 0 || strstr($range, '-') === false) {
throw new Exception('Invalid range', 416);
}
$rangeStart = (int) $rangeStart;

View file

@ -338,6 +338,7 @@ App::error(function ($error, $utopia, $request, $response, $layout, $project) {
case 404: // Error allowed publicly
case 409: // Error allowed publicly
case 412: // Error allowed publicly
case 416: // Error allowed publicly
case 429: // Error allowed publicly
case 501: // Error allowed publicly
case 503: // Error allowed publicly

View file

@ -304,8 +304,8 @@ trait StorageBase
'x-appwrite-project' => $this->getProject()['$id'],
'Range' => 'bytes=0-',
], $this->getHeaders()));
$this->assertEquals(400, $file52['headers']['status-code']);
$this->assertEquals(206, $file52['headers']['status-code']);
// Test ranged download - with invalid range
$file53 = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $data['fileId'] . '/download', array_merge([
@ -314,7 +314,7 @@ trait StorageBase
'Range' => 'bytes=988',
], $this->getHeaders()));
$this->assertEquals(400, $file53['headers']['status-code']);
$this->assertEquals(416, $file53['headers']['status-code']);
// Test ranged download - with invalid range
$file54 = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $data['fileId'] . '/download', array_merge([
@ -323,7 +323,7 @@ trait StorageBase
'Range' => 'bytes=-988',
], $this->getHeaders()));
$this->assertEquals(400, $file54['headers']['status-code']);
$this->assertEquals(416, $file54['headers']['status-code']);
$file6 = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $data['fileId'] . '/view', array_merge([
'content-type' => 'application/json',