Spaces:
Running on CPU Upgrade
Running on CPU Upgrade
Download app/request_context.py from DanielKretschmer/lighting-mvp: direct link, hf CLI and curl.
- Browser
- Download file 552 Bytes
-
https://huggingface.co/spaces/DanielKretschmer/lighting-mvp/resolve/main/app/request_context.py
- Command line
-
hf download hf://spaces/DanielKretschmer/lighting-mvp/app/request_context.py
-
curl -L -o request_context.py https://huggingface.co/spaces/DanielKretschmer/lighting-mvp/resolve/main/app/request_context.py
552 Bytes
| """Per-request context shared between the access-gate middleware and the | |
| mounted MCP server. | |
| The middleware authenticates every request (cookie or bearer token) and stows | |
| the resolved user here; MCP tools — which run inside the mounted Streamable | |
| HTTP sub-app and don't see FastAPI's ``request.state`` directly — read it back | |
| to act as the authenticated operator. | |
| """ | |
| from __future__ import annotations | |
| from contextvars import ContextVar | |
| from typing import Any | |
| current_user_ctx: ContextVar[Any | None] = ContextVar("current_user", default=None) | |