Files

14 lines
538 B
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""路由层透传信息提取:投顾 JWT 与 trace_id(供 Agent 客户端透传)。"""
from __future__ import annotations
from fastapi import Request
from utils.request_id import get_request_id, new_request_id
def extract_auth(request: Request) -> tuple[str, str]:
"""返回 (Authorization 头原值, trace_id);trace_id 优先透传,无则生成。"""
auth = request.headers.get("Authorization", "")
trace_id = request.headers.get("X-Trace-Id") or get_request_id() or new_request_id()
return auth, trace_id