From cf8a2e0ce5220349f6ee2055f51b13e0ed80e41c Mon Sep 17 00:00:00 2001 From: vvzvlad Date: Mon, 6 Apr 2026 23:29:35 +0300 Subject: [PATCH] feat(api): add immutable cache header to file responses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add a Cache‑Control header with `public, max-age=86400, immutable` to file responses, allowing clients to cache files for a day --- api_server.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/api_server.py b/api_server.py index c53a2af..e31a424 100644 --- a/api_server.py +++ b/api_server.py @@ -218,7 +218,12 @@ async def prepare_file_response(file_path: str, delete_after: bool = False) -> F if not media_type: media_type = "application/octet-stream" # Final fallback to octet-stream logger.debug(f"Determined media type for {os.path.basename(file_path)}: {media_type}") - headers = {"Content-Disposition": f"inline; filename={os.path.basename(file_path)}"} + headers = { + "Content-Disposition": f"inline; filename={os.path.basename(file_path)}", + # Files are addressed by file_unique_id which is immutable in Telegram, + # so it is safe to cache them aggressively on the client side. + "Cache-Control": "public, max-age=86400, immutable", + } if delete_after: return FileResponse(path=file_path, media_type=media_type, headers=headers, background=BackgroundTask(delayed_delete_file, file_path)) else: