cors.py
file-level
1
files
1
commits
0
hotspots
0
🧊 dead
0
💥 blast risk
| 1 | """CORS policy for the local app server (§Q0.5).""" |
| 2 | |
| 3 | from __future__ import annotations |
| 4 | |
| 5 | |
| 6 | def allowed_origins(port: int) -> frozenset[str]: |
| 7 | """Return the frozen allowlist of browser origins.""" |
| 8 | return frozenset( |
| 9 | { |
| 10 | f"http://127.0.0.1:{port}", |
| 11 | f"http://localhost:{port}", |
| 12 | f"http://[::1]:{port}", |
| 13 | } |
| 14 | ) |
| 15 | |
| 16 | |
| 17 | def origin_allowed(origin: str | None, port: int) -> bool: |
| 18 | """Return whether ``origin`` is permitted for this server instance.""" |
| 19 | if not origin: |
| 20 | return True |
| 21 | return origin in allowed_origins(port) |