24 lines
804 B
Python
24 lines
804 B
Python
"""项目出站代理策略;OTel exporter 不使用这里的配置。"""
|
|
from __future__ import annotations
|
|
|
|
from typing import TYPE_CHECKING
|
|
|
|
if TYPE_CHECKING:
|
|
from app.shared.config import Settings
|
|
|
|
|
|
def httpx_client_options(
|
|
settings: "Settings", *, target_url: str | None = None
|
|
) -> dict[str, object]:
|
|
"""返回 HTTPX 客户端统一的代理与环境变量策略。"""
|
|
proxy = None if target_url and settings.proxy_bypasses(target_url) else settings.httpx_proxy
|
|
options: dict[str, object] = {"trust_env": False}
|
|
if proxy is not None:
|
|
options["proxy"] = proxy
|
|
return options
|
|
|
|
|
|
def playwright_launch_proxy(settings: "Settings") -> dict[str, str] | None:
|
|
"""返回 Playwright 启动参数使用的统一代理设置。"""
|
|
return settings.playwright_proxy
|