19 lines
617 B
Python
19 lines
617 B
Python
"""代理 URL 与 httpx 的兼容处理。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
|
|
def httpx_proxy_url(proxy_url: str | None) -> str | None:
|
|
"""
|
|
将配置中的代理地址转为 httpx 可用的形式。
|
|
|
|
部分环境(socksio / httpx)不支持 ``socks5h://`` scheme,会报
|
|
``Unknown scheme for proxy URL``;此时退化为 ``socks5://``(域名在本机解析后再走 SOCKS)。
|
|
"""
|
|
if not proxy_url or not str(proxy_url).strip():
|
|
return None
|
|
u = str(proxy_url).strip()
|
|
if u.startswith("socks5h://"):
|
|
return "socks5://" + u[len("socks5h://") :]
|
|
return u
|