mirror of
https://git.datalinker.icu/comfyanonymous/ComfyUI
synced 2026-08-16 05:10:03 +08:00
refactor: based on code review feedback
This commit is contained in:
parent
0e524c8c28
commit
a7592defd2
16
server.py
16
server.py
@ -57,19 +57,15 @@ async def cache_control(request: web.Request, handler: Callable[[web.Request], A
|
||||
if request.path.endswith('.js') or request.path.endswith('.css') or request.path.endswith('index.json'):
|
||||
response.headers.setdefault('Cache-Control', 'no-cache')
|
||||
elif request.path.lower().endswith(IMG_EXTENSIONS):
|
||||
if response.status == 304:
|
||||
# 304 Not Modified - don't set cache headers, inherit from original
|
||||
pass
|
||||
elif response.status == 404:
|
||||
if response.status == 404:
|
||||
response.headers.setdefault('Cache-Control', f"public, max-age={ONE_HOUR}")
|
||||
elif 200 <= response.status < 300:
|
||||
elif response.status in (200, 201, 202, 203, 204, 205, 206, 301, 308):
|
||||
# Success responses and permanent redirects - cache for 1 day
|
||||
response.headers.setdefault('Cache-Control', f"public, max-age={ONE_DAY}")
|
||||
elif response.status == 301 or response.status == 308:
|
||||
# Permanent redirects - cache for 1 day
|
||||
response.headers.setdefault('Cache-Control', f"public, max-age={ONE_DAY}")
|
||||
elif 300 <= response.status < 400:
|
||||
# Temporary redirects (302, 303, 307) and other 3xx - no cache
|
||||
elif response.status in (302, 303, 307):
|
||||
# Temporary redirects - no cache
|
||||
response.headers.setdefault('Cache-Control', 'no-cache')
|
||||
# Note: 304 Not Modified falls through - no cache headers set
|
||||
|
||||
return response
|
||||
|
||||
|
||||
@ -7,10 +7,8 @@ from unittest.mock import patch
|
||||
pytestmark = pytest.mark.asyncio # Apply asyncio mark to all tests
|
||||
|
||||
# Mock the problematic imports before importing server
|
||||
with patch('app.frontend_management.FrontendManager'):
|
||||
with patch('utils.install_util.get_missing_requirements_message'):
|
||||
with patch('utils.install_util.requirements_path'):
|
||||
from server import cache_control, ONE_HOUR, ONE_DAY, IMG_EXTENSIONS
|
||||
with patch('app.frontend_management.FrontendManager'), patch('utils.install_util.get_missing_requirements_message'), patch('utils.install_util.requirements_path'):
|
||||
from server import cache_control, ONE_HOUR, ONE_DAY, IMG_EXTENSIONS
|
||||
|
||||
|
||||
class TestCacheControl:
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user