From 4b2faa87bb9e28c631a63207dff596be2cd57203 Mon Sep 17 00:00:00 2001 From: 3252a8 <3252a8@proton.me> Date: Fri, 5 Jun 2026 15:47:37 +0300 Subject: [PATCH] fix: refresh current favicon aliases --- backend/bot/app/web/webapp/assets.py | 8 ++++++-- tests/test_webapp_assets.py | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/backend/bot/app/web/webapp/assets.py b/backend/bot/app/web/webapp/assets.py index 9cf8145..def7360 100644 --- a/backend/bot/app/web/webapp/assets.py +++ b/backend/bot/app/web/webapp/assets.py @@ -382,11 +382,15 @@ async def webapp_current_favicon_route(request: web.Request) -> web.Response: favicon_url = _resolve_webapp_favicon_url(settings, _resolve_webapp_logo_url(settings)) digest = _webapp_generated_favicon_digest(favicon_url) if digest: - return _webapp_favicon_file_response(digest, target_filename) + response = _webapp_favicon_file_response(digest, target_filename) + response.headers["Cache-Control"] = "no-cache" + return response redirect_url = _webapp_redirectable_favicon_url(favicon_url, target_filename) if redirect_url: - raise web.HTTPFound(location=redirect_url) + redirect = web.HTTPFound(location=redirect_url) + redirect.headers["Cache-Control"] = "no-cache" + raise redirect raise web.HTTPNotFound(text="webapp_favicon_not_found") diff --git a/tests/test_webapp_assets.py b/tests/test_webapp_assets.py index 6a4e14a..71171d3 100644 --- a/tests/test_webapp_assets.py +++ b/tests/test_webapp_assets.py @@ -10,6 +10,7 @@ from pathlib import Path from types import SimpleNamespace from unittest.mock import AsyncMock, patch +from aiohttp import web from PIL import Image, ImageOps from bot.app.web import subscription_webapp @@ -476,6 +477,7 @@ class WebAppAssetTests(unittest.IsolatedAsyncioTestCase): self.assertEqual(response.status, 200) self.assertEqual(response.content_type, "image/png") self.assertEqual(response.body, b"touch-icon") + self.assertEqual(response.headers["Cache-Control"], "no-cache") async def test_current_favicon_alias_serves_default_icon_when_unconfigured(self): settings = SimpleNamespace( @@ -492,6 +494,23 @@ class WebAppAssetTests(unittest.IsolatedAsyncioTestCase): self.assertEqual(response.status, 200) self.assertEqual(response.content_type, "image/png") self.assertGreater(len(response.body), 0) + self.assertEqual(response.headers["Cache-Control"], "no-cache") + + async def test_current_favicon_alias_redirect_is_not_cached(self): + settings = SimpleNamespace( + WEBAPP_ENABLED=True, + WEBAPP_LOGO_URL="", + WEBAPP_FAVICON_USE_CUSTOM=True, + WEBAPP_FAVICON_URL="/uploaded-icon.png", + WEBAPP_LOGO_FAVICON_URL="", + ) + request = SimpleNamespace(app={"settings": settings}, path="/icon-192.png") + + with self.assertRaises(web.HTTPFound) as exc: + await webapp_assets.webapp_current_favicon_route(request) + + self.assertEqual(exc.exception.location, "/uploaded-icon.png") + self.assertEqual(exc.exception.headers["Cache-Control"], "no-cache") async def test_default_logo_route_serves_bundled_logo(self): settings = SimpleNamespace(WEBAPP_ENABLED=True)