feat(api): add immutable cache header to file responses

Add a Cache‑Control header with `public, max-age=86400, immutable`
to file responses, allowing clients to cache files for a day
This commit is contained in:
vvzvlad
2026-04-06 23:29:35 +03:00
parent c9b0d2ffc9
commit cf8a2e0ce5
+6 -1
View File
@@ -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: