fix: refresh current favicon aliases

This commit is contained in:
3252a8
2026-06-05 15:47:37 +03:00
parent 1200e8ff70
commit 4b2faa87bb
2 changed files with 25 additions and 2 deletions
+6 -2
View File
@@ -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)) favicon_url = _resolve_webapp_favicon_url(settings, _resolve_webapp_logo_url(settings))
digest = _webapp_generated_favicon_digest(favicon_url) digest = _webapp_generated_favicon_digest(favicon_url)
if digest: 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) redirect_url = _webapp_redirectable_favicon_url(favicon_url, target_filename)
if redirect_url: 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") raise web.HTTPNotFound(text="webapp_favicon_not_found")
+19
View File
@@ -10,6 +10,7 @@ from pathlib import Path
from types import SimpleNamespace from types import SimpleNamespace
from unittest.mock import AsyncMock, patch from unittest.mock import AsyncMock, patch
from aiohttp import web
from PIL import Image, ImageOps from PIL import Image, ImageOps
from bot.app.web import subscription_webapp from bot.app.web import subscription_webapp
@@ -476,6 +477,7 @@ class WebAppAssetTests(unittest.IsolatedAsyncioTestCase):
self.assertEqual(response.status, 200) self.assertEqual(response.status, 200)
self.assertEqual(response.content_type, "image/png") self.assertEqual(response.content_type, "image/png")
self.assertEqual(response.body, b"touch-icon") 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): async def test_current_favicon_alias_serves_default_icon_when_unconfigured(self):
settings = SimpleNamespace( settings = SimpleNamespace(
@@ -492,6 +494,23 @@ class WebAppAssetTests(unittest.IsolatedAsyncioTestCase):
self.assertEqual(response.status, 200) self.assertEqual(response.status, 200)
self.assertEqual(response.content_type, "image/png") self.assertEqual(response.content_type, "image/png")
self.assertGreater(len(response.body), 0) 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): async def test_default_logo_route_serves_bundled_logo(self):
settings = SimpleNamespace(WEBAPP_ENABLED=True) settings = SimpleNamespace(WEBAPP_ENABLED=True)