"""图片请求头构建(Cookie 由 extension_cookies 在失败时补充)。""" from __future__ import annotations def normalize_image_url(url: str) -> str: url = (url or "").strip() if url.startswith("//"): return "https:" + url return url def image_request_headers( *, cookie_header: str | None = None, accept: str = "image/avif,image/webp,image/apng,image/*,*/*;q=0.8", ) -> dict[str, str]: from xhs_bridge.browser_profile import build_browser_headers, resolve_profile_for_request from xhs_bridge.config import load_config profile = resolve_profile_for_request(load_config()) return build_browser_headers( profile=profile, cookie_header=cookie_header or None, with_cookie=False, accept=accept, extra={ "Sec-Fetch-Dest": "image", "Sec-Fetch-Mode": "no-cors", "Sec-Fetch-Site": "cross-site", }, )