INNER CODE UNIT · Python
_read
ArcReel/ArcReel · server/app.py:716
def _read() -> tuple[bool, str]:
if not template_path.exists():
return False, ""
return True, template_path.read_text(encoding="utf-8")
exists, template = await asyncio.to_thread(_read)
if not exists:
return PlainTextResponse("Agent 安装指引不存在", status_code=404)
# 从请求推断 base URL;仅信任 x-forwarded-proto(反向代理标准头),
# host 使用连接实际目标地址,不接受可被用户伪造的 x-forwarded-host。
forwarded_proto = request.headers.get("x-forwarded-proto")
scheme = forwarded_proto or request.url.scheme or "http"
host = request.url.netloc
base_url = f"{scheme}://{host}"
content = template.replace("{{BASE_URL}}", base_url)
return PlainTextResponse(content, media_type="text/markdown; charset=utf-8")