Use Claude Code, Codex, VSCode, Pi, and OpenCode (and 6 other harnesses) for free (1.3B+ free tokens) from your terminal, app, IDE, or phone, and now from the browser with native browser sessions (multi-harness + multi-model) like OpenClaw (voice supported + ToS friendly)
Python
Prevent the admin UI from being served from cache (#1160)
Ali Khokhare14d8402a1d2
diff --git a/pyproject.toml b/pyproject.tomlindex f60c1972..815f3150 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -4,7 +4,7 @@ build-backend = "hatchling.build"[project]name = "free-claude-code"-version = "4.8.2"+version = "4.8.3"description = "Local proxy connecting coding agents to OpenAI-compatible AI providers"readme = "README.md"requires-python = ">=3.14.0"diff --git a/src/free_claude_code/api/admin_cache.py b/src/free_claude_code/api/admin_cache.pynew file mode 100644index 00000000..3ac51c79--- /dev/null+++ b/src/free_claude_code/api/admin_cache.py@@ -0,0 +1,49 @@+"""Admin response cache policy."""++from fastapi import Response+from starlette.datastructures import MutableHeaders+from starlette.types import ASGIApp, Message, Receive, Scope, Send++_ADMIN_CACHE_CONTROL = "no-store"+++class AdminNoStoreMiddleware:+ """Prevent browsers from retaining responses from the admin surface."""++ def __init__(self, app: ASGIApp) -> None:+ self._app = app++ async def __call__(+ self,+ scope: Scope,+ receive: Receive,+ send: Send,+ ) -> None:+ path = scope.get("path", "")+ if scope["type"] != "http" or not _is_admin_path(path):+ await self._app(scope, receive, send)+ return++ async def send_without_cache(message: Message) -> None:+ if message["type"] == "http.response.start":+ message = dict(message)+ raw_headers = list(message.get("headers", ()))+ _set_no_store(MutableHeaders(raw=raw_headers))+ message["headers"] = raw_headers+ await send(message)++ await self._app(scope, receive, send_without_cache)+++def attach_admin_no_store(response: Response, *, path: str) -> None:+ """Attach the policy when an outer server-error boundary bypasses middleware."""+ if _is_admin_path(path):+ _set_no_store(response.headers)+++def _is_admin_path(path: str) -> bool:+ return path == "/admin" or path.startswith("/admin/")+++def _set_no_store(headers: MutableHeaders) -> None:+ headers["Cache-Control"] = _ADMIN_CACHE_CONTROLdiff --git a/src/free_claude_code/api/admin_static/admin.js b/src/free_claude_code/api/admin_static/admin.jsindex c4124a07..2a4faf0f 100644--- a/src/free_claude_code/api/admin_static/admin.js+++ b/src/free_claude_code/api/admin_static/admin.js@@ -69,6 +69,7 @@ async function api(path, options = {}) {const response = await fetch(path, {headers: { "Content-Type": "application/json", ...(options.headers || {}) },...options,+ cache: "no-store",});if (!response.ok) {throw new Error(`${response.status} ${response.statusText}`);diff --git a/src/free_claude_code/api/app.py b/src/free_claude_code/api/app.pyindex 330bdd1f..193ab89d 100644--- a/src/free_claude_code/api/app.py+++ b/src/free_claude_code/api/app.py@@ -21,6 +21,7 @@ from free_claude_code.core.trace import ()from free_claude_code.core.version import package_version+from .admin_cache import AdminNoStoreMiddleware, attach_admin_no_storefrom .admin_routes import router as admin_routerfrom .ports import ApiServicesfrom .request_errors import ordinary_application_error_response@@ -38,6 +39,7 @@ def create_app(services: ApiServices) -> FastAPI:app = FastAPI(title="Claude Code Proxy", version=package_version())app.state.services = servicesapp.add_middleware(RequestCorrelationMiddleware)+ app.add_middleware(AdminNoStoreMiddleware)app.include_router(admin_router)app.include_router(router)@@ -108,6 +110,7 @@ def create_app(services: ApiServices) -> FastAPI:request_id=request_id,)response = JSONResponse(status_code=500, content=content)+ attach_admin_no_store(response, path=request.url.path)attach_request_id_headers(response,request_id=request_id,diff --git a/tests/api/test_admin.py b/tests/api/test_admin.pyindex 250da089..d7f6247e 100644--- a/tests/api/test_admin.py+++ b/tests/api/test_admin.py@@ -61,6 +61,94 @@ def test_admin_page_is_loopback_only(monkeypatch, tmp_path):assert remote_client.get("/admin").status_code == 403+ "path",+ (+ "/admin",+ "/admin/assets/admin.css",+ "/admin/assets/admin.js",+ "/admin/api/config",+ ),+)+def test_admin_responses_are_never_cached(monkeypatch, tmp_path, path):+ _set_home(monkeypatch, tmp_path)+ response = _local_client(create_test_app()).get(path)++ assert response.status_code == 200+ assert response.headers["cache-control"] == "no-store"+++ ("path", "client_host", "expected_status"),+ (+ ("/admin", "203.0.113.10", 403),+ ("/admin/assets/missing.js", "127.0.0.1", 404),+ ),+)+def test_admin_http_errors_are_never_cached(+ monkeypatch,+ tmp_path,+ path,+ client_host,+ expected_status,+):+ _set_home(monkeypatch, tmp_path)+ client = TestClient(create_test_app(), client=(client_host, 50000))++ response = client.get(path)++ assert response.status_code == expected_status+ assert response.headers["cache-control"] == "no-store"+++def test_admin_validation_errors_are_never_cached(monkeypatch, tmp_path):+ _set_home(monkeypatch, tmp_path)++ response = _local_client(create_test_app()).post(+ "/admin/api/config/validate",+ content="{",+ headers={"Content-Type": "application/json"},+ )++ assert response.status_code == 422+ assert response.headers["cache-control"] == "no-store"+++def test_admin_unexpected_errors_are_never_cached(monkeypatch, tmp_path):+ _set_home(monkeypatch, tmp_path)+ client = TestClient(+ create_test_app(),+ client=("127.0.0.1", 50000),+ raise_server_exceptions=False,+ )++ with patch(+ "free_claude_code.api.admin_routes.load_config_response",+ side_effect=RuntimeError("test error"),+ ):+ response = client.get("/admin/api/config")++ assert response.status_code == 500+ assert response.headers["cache-control"] == "no-store"+++def test_admin_cache_policy_does_not_match_similar_public_paths(monkeypatch, tmp_path):+ _set_home(monkeypatch, tmp_path)++ response = _local_client(create_test_app()).get("/administrator")++ assert response.status_code == 404+ assert "cache-control" not in response.headers+++def test_admin_api_fetches_bypass_browser_cache():+ script = Path("src/free_claude_code/api/admin_static/admin.js").read_text(+ encoding="utf-8"+ )++ assert 'cache: "no-store"' in script++def test_admin_page_no_longer_renders_generated_env_panel(monkeypatch, tmp_path):_set_home(monkeypatch, tmp_path)app = create_test_app()diff --git a/uv.lock b/uv.lockindex d096616b..59c0c65f 100644--- a/uv.lock+++ b/uv.lock@@ -561,7 +561,7 @@ wheels = [[[package]]name = "free-claude-code"-version = "4.8.2"+version = "4.8.3"source = { editable = "." }dependencies = [{ name = "aiohttp" },