fix range header
This commit is contained in:
parent
f924ead8f8
commit
9052d34b33
2 changed files with 34 additions and 2 deletions
|
@ -30,6 +30,8 @@ use Utopia\Validator\Range;
|
|||
use Utopia\Validator\Text;
|
||||
use Utopia\Validator\WhiteList;
|
||||
|
||||
use function PHPUnit\Framework\isNull;
|
||||
|
||||
App::post('/v1/storage/buckets')
|
||||
->desc('Create storage bucket')
|
||||
->groups(['api', 'storage'])
|
||||
|
@ -1067,9 +1069,12 @@ 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 || strlen($rangeEnd) == 0) {
|
||||
throw new Exception('Invalid range', 400);
|
||||
}
|
||||
$rangeStart = (int) $rangeStart;
|
||||
$rangeEnd = (int) $rangeEnd;
|
||||
if(($rangeStart > $rangeEnd) || $rangeEnd > $size) {
|
||||
if(($rangeStart >= $rangeEnd) || $rangeEnd > $size) {
|
||||
throw new Exception('Invalid range', 400);
|
||||
}
|
||||
|
||||
|
|
|
@ -298,6 +298,33 @@ trait StorageBase
|
|||
$this->assertNotEmpty($file51['body']);
|
||||
$this->assertEquals($originalChunk, $file51['body']);
|
||||
|
||||
// Test ranged download - with invalid range
|
||||
$file52 = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $data['fileId'] . '/download', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'Range' => 'bytes=0-',
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals(400, $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([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'Range' => 'bytes=988',
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals(400, $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([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
'Range' => 'bytes=-988',
|
||||
], $this->getHeaders()));
|
||||
|
||||
$this->assertEquals(400, $file54['headers']['status-code']);
|
||||
|
||||
$file6 = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $data['fileId'] . '/view', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
|
|
Loading…
Reference in a new issue