Test storage preview cache headers

This commit is contained in:
Chirag Aggarwal
2026-05-08 10:04:40 +05:30
parent 5841d0a944
commit 48e2ee9acb
@@ -957,6 +957,64 @@ trait StorageBase
$this->assertNotEquals($imageBefore->getImageBlob(), $imageAfter->getImageBlob());
}
public function testFilePreviewCacheControlOnCacheHit(): void
{
$data = $this->setupBucketFile();
$bucketId = $data['bucketId'];
$file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', array_merge([
'content-type' => 'multipart/form-data',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders()), [
'fileId' => ID::unique(),
'file' => new CURLFile(realpath(__DIR__ . '/../../../resources/logo.png'), 'image/png', 'logo.png'),
'permissions' => [
Permission::read(Role::any()),
Permission::update(Role::any()),
Permission::delete(Role::any()),
],
]);
$this->assertEquals(201, $file['headers']['status-code']);
$this->assertNotEmpty($file['body']['$id']);
$fileId = $file['body']['$id'];
$params = [
'width' => 123,
'height' => 45,
'output' => 'png',
'quality' => 80,
];
$headers = array_merge([
'content-type' => 'application/json',
'x-appwrite-project' => $this->getProject()['$id'],
], $this->getHeaders());
$preview = $this->client->call(
Client::METHOD_GET,
'/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview',
$headers,
$params
);
$this->assertEquals(200, $preview['headers']['status-code']);
$this->assertEquals('image/png', $preview['headers']['content-type']);
$this->assertEquals('private, max-age=2592000', $preview['headers']['cache-control']);
$this->assertArrayNotHasKey('x-appwrite-cache', $preview['headers']);
$this->assertNotEmpty($preview['body']);
$cachedPreview = $this->client->call(
Client::METHOD_GET,
'/storage/buckets/' . $bucketId . '/files/' . $fileId . '/preview',
$headers,
$params
);
$this->assertEquals(200, $cachedPreview['headers']['status-code']);
$this->assertEquals('image/png', $cachedPreview['headers']['content-type']);
$this->assertEquals('hit', $cachedPreview['headers']['x-appwrite-cache']);
$this->assertEquals('private, max-age=15552000', $cachedPreview['headers']['cache-control']);
$this->assertEquals($preview['body'], $cachedPreview['body']);
}
public function testFilePreviewZstdCompression(): void
{
$data = $this->setupZstdCompressionBucket();