diff --git a/app/controllers/api/avatars.php b/app/controllers/api/avatars.php index fcff3e4179..dadd9da5e3 100644 --- a/app/controllers/api/avatars.php +++ b/app/controllers/api/avatars.php @@ -55,7 +55,7 @@ $avatarCallback = function (string $type, string $code, int $width, int $height, $output = (empty($output)) ? $type : $output; $data = $image->output($output, $quality); $response - ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + 60 * 60 * 24 * 30) . ' GMT') + ->addHeader('Cache-Control', 'private, max-age=2592000') // 30 days ->setContentType('image/png') ->file($data); unset($image); @@ -275,7 +275,7 @@ App::get('/v1/avatars/image') $data = $image->output($output, $quality); $response - ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + 60 * 60 * 24 * 30) . ' GMT') + ->addHeader('Cache-Control', 'private, max-age=2592000') // 30 days ->setContentType('image/png') ->file($data); unset($image); @@ -409,7 +409,7 @@ App::get('/v1/avatars/favicon') throw new Exception(Exception::AVATAR_ICON_NOT_FOUND, 'Favicon not found'); } $response - ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + 60 * 60 * 24 * 30) . ' GMT') + ->addHeader('Cache-Control', 'private, max-age=2592000') // 30 days ->setContentType('image/x-icon') ->file($data); } @@ -420,7 +420,7 @@ App::get('/v1/avatars/favicon') $data = $image->output($output, $quality); $response - ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + 60 * 60 * 24 * 30) . ' GMT') + ->addHeader('Cache-Control', 'private, max-age=2592000') // 30 days ->setContentType('image/png') ->file($data); unset($image); @@ -461,7 +461,7 @@ App::get('/v1/avatars/qr') $image->crop((int) $size, (int) $size); $response - ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)) . ' GMT') // 45 days cache + ->addHeader('Cache-Control', 'private, max-age=3888000') // 45 days ->setContentType('image/png') ->send($image->output('png', 9)); }); @@ -544,7 +544,7 @@ App::get('/v1/avatars/initials') $image->compositeImage($punch, Imagick::COMPOSITE_COPYOPACITY, 0, 0); $response - ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)) . ' GMT') // 45 days cache + ->addHeader('Cache-Control', 'private, max-age=3888000') // 45 days ->setContentType('image/png') ->file($image->getImageBlob()); }); @@ -751,7 +751,7 @@ App::get('/v1/cards/cloud') } $response - ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)) . ' GMT') // 45 days cache + ->addHeader('Cache-Control', 'private, max-age=3888000') // 45 days ->setContentType('image/png') ->file($baseImage->getImageBlob()); }); @@ -829,7 +829,7 @@ App::get('/v1/cards/cloud-back') } $response - ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)) . ' GMT') // 45 days cache + ->addHeader('Cache-Control', 'private, max-age=3888000') // 45 days ->setContentType('image/png') ->file($baseImage->getImageBlob()); }); @@ -1219,7 +1219,7 @@ App::get('/v1/cards/cloud-og') } $response - ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)) . ' GMT') // 45 days cache + ->addHeader('Cache-Control', 'private, max-age=3888000') // 45 days ->setContentType('image/png') ->file($baseImage->getImageBlob()); }); diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index c3051ef476..396d2048f2 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -994,7 +994,7 @@ App::get('/v1/functions/:functionId/deployments/:deploymentId/download') $response ->setContentType('application/gzip') - ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)) . ' GMT') // 45 days cache + ->addHeader('Cache-Control', 'private, max-age=3888000') // 45 days ->addHeader('X-Peak', \memory_get_peak_usage()) ->addHeader('Content-Disposition', 'attachment; filename="' . $deploymentId . '.tar.gz"'); diff --git a/app/controllers/api/locale.php b/app/controllers/api/locale.php index 2917bc8416..1f042d2239 100644 --- a/app/controllers/api/locale.php +++ b/app/controllers/api/locale.php @@ -63,7 +63,7 @@ App::get('/v1/locale') $response ->addHeader('Cache-Control', 'public, max-age=' . $time) - ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + $time) . ' GMT') // 45 days cache + ->addHeader('Cache-Control', 'private, max-age=3888000') // 45 days ; $response->dynamic(new Document($output), Response::MODEL_LOCALE); }); diff --git a/app/controllers/api/storage.php b/app/controllers/api/storage.php index c3d57e5470..5261f9c89a 100644 --- a/app/controllers/api/storage.php +++ b/app/controllers/api/storage.php @@ -999,7 +999,7 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/preview') $contentType = (\array_key_exists($output, $outputs)) ? $outputs[$output] : $outputs['jpg']; $response - ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + 60 * 60 * 24 * 30) . ' GMT') + ->addHeader('Cache-Control', 'private, max-age=2592000') // 30 days ->setContentType($contentType) ->file($data) ; @@ -1062,7 +1062,7 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/download') $response ->setContentType($file->getAttribute('mimeType')) - ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)) . ' GMT') // 45 days cache + ->addHeader('Cache-Control', 'private, max-age=3888000') // 45 days ->addHeader('X-Peak', \memory_get_peak_usage()) ->addHeader('Content-Disposition', 'attachment; filename="' . $file->getAttribute('name', '') . '"') ; @@ -1212,7 +1212,7 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/view') ->addHeader('Content-Security-Policy', 'script-src none;') ->addHeader('X-Content-Type-Options', 'nosniff') ->addHeader('Content-Disposition', 'inline; filename="' . $file->getAttribute('name', '') . '"') - ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)) . ' GMT') // 45 days cache + ->addHeader('Cache-Control', 'private, max-age=3888000') // 45 days ->addHeader('X-Peak', \memory_get_peak_usage()) ; @@ -1366,7 +1366,7 @@ App::get('/v1/storage/buckets/:bucketId/files/:fileId/push') ->addHeader('Content-Security-Policy', 'script-src none;') ->addHeader('X-Content-Type-Options', 'nosniff') ->addHeader('Content-Disposition', 'inline; filename="' . $file->getAttribute('name', '') . '"') - ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + (60 * 60 * 24 * 45)) . ' GMT') // 45 days cache + ->addHeader('Cache-Control', 'private, max-age=3888000') // 45 days ->addHeader('X-Peak', \memory_get_peak_usage()); $size = $file->getAttribute('sizeOriginal', 0); diff --git a/app/controllers/shared/api.php b/app/controllers/shared/api.php index f0d896c95a..7a5de8af19 100644 --- a/app/controllers/shared/api.php +++ b/app/controllers/shared/api.php @@ -508,7 +508,7 @@ App::init() } $response - ->addHeader('Expires', \date('D, d M Y H:i:s', \time() + $timestamp) . ' GMT') + ->addHeader('Cache-Control', sprintf('private, max-age=%d', $timestamp)) ->addHeader('X-Appwrite-Cache', 'hit') ->setContentType($cacheLog->getAttribute('mimeType')) ->send($data); @@ -516,7 +516,7 @@ App::init() $response ->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate') ->addHeader('Pragma', 'no-cache') - ->addHeader('Expires', 0) + ->addHeader('Expires', '0') ->addHeader('X-Appwrite-Cache', 'miss') ; }