From bad74bd0b81db94c260fbca1af863dab45f21fde Mon Sep 17 00:00:00 2001 From: Hemachandar Date: Tue, 14 Oct 2025 18:18:41 +0530 Subject: [PATCH 1/3] Add cache header for deployment download API --- .../Platform/Modules/Sites/Http/Deployments/Download/Get.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php index 5a87ce453f..1a3446d175 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php @@ -104,9 +104,7 @@ class Get extends Action $response ->setContentType('application/gzip') - ->addHeader('Cache-Control', 'no-cache, no-store, must-revalidate') - ->addHeader('Expires', '0') - ->addHeader('Pragma', 'no-cache') + ->addHeader('Cache-Control', 'private, max-age=3888000') // 45 days ->addHeader('X-Peak', \memory_get_peak_usage()) ->addHeader('Content-Disposition', 'attachment; filename="' . $deploymentId . '-' . $type . '.tar.gz"'); From 9f07a2bca4cce72ffe12254c2b5abe38743390b9 Mon Sep 17 00:00:00 2001 From: Hemachandar Date: Wed, 15 Oct 2025 15:16:28 +0530 Subject: [PATCH 2/3] early return --- .../Modules/Sites/Http/Deployments/Download/Get.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php index 1a3446d175..8fb1f6c7c8 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php @@ -102,12 +102,6 @@ class Get extends Action throw new Exception(Exception::DEPLOYMENT_NOT_FOUND); } - $response - ->setContentType('application/gzip') - ->addHeader('Cache-Control', 'private, max-age=3888000') // 45 days - ->addHeader('X-Peak', \memory_get_peak_usage()) - ->addHeader('Content-Disposition', 'attachment; filename="' . $deploymentId . '-' . $type . '.tar.gz"'); - $size = $device->getFileSize($path); $rangeHeader = $request->getHeader('range'); @@ -131,8 +125,15 @@ class Get extends Action ->setStatusCode(Response::STATUS_CODE_PARTIALCONTENT); $response->send($device->read($path, $start, ($end - $start + 1))); + return; } + $response + ->setContentType('application/gzip') + ->addHeader('Cache-Control', 'private, max-age=3888000') // 45 days + ->addHeader('X-Peak', \memory_get_peak_usage()) + ->addHeader('Content-Disposition', 'attachment; filename="' . $deploymentId . '-' . $type . '.tar.gz"'); + if ($size > APP_STORAGE_READ_BUFFER) { for ($i = 0; $i < ceil($size / MAX_OUTPUT_CHUNK_SIZE); $i++) { $response->chunk( From 635d77350aef62657aee4a96d2e30b725d163a95 Mon Sep 17 00:00:00 2001 From: Hemachandar Date: Wed, 15 Oct 2025 16:05:34 +0530 Subject: [PATCH 3/3] set header --- .../Modules/Sites/Http/Deployments/Download/Get.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php index 8fb1f6c7c8..d4e6fda411 100644 --- a/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php +++ b/src/Appwrite/Platform/Modules/Sites/Http/Deployments/Download/Get.php @@ -105,6 +105,12 @@ class Get extends Action $size = $device->getFileSize($path); $rangeHeader = $request->getHeader('range'); + $response + ->setContentType('application/gzip') + ->addHeader('Cache-Control', 'private, max-age=3888000') // 45 days + ->addHeader('X-Peak', \memory_get_peak_usage()) + ->addHeader('Content-Disposition', 'attachment; filename="' . $deploymentId . '-' . $type . '.tar.gz"'); + if (!empty($rangeHeader)) { $start = $request->getRangeStart(); $end = $request->getRangeEnd(); @@ -128,12 +134,6 @@ class Get extends Action return; } - $response - ->setContentType('application/gzip') - ->addHeader('Cache-Control', 'private, max-age=3888000') // 45 days - ->addHeader('X-Peak', \memory_get_peak_usage()) - ->addHeader('Content-Disposition', 'attachment; filename="' . $deploymentId . '-' . $type . '.tar.gz"'); - if ($size > APP_STORAGE_READ_BUFFER) { for ($i = 0; $i < ceil($size / MAX_OUTPUT_CHUNK_SIZE); $i++) { $response->chunk(