feat(api): improve timeout handling in BaseRequest class

Updated the BaseRequest class to conditionally include the timeout parameter when making requests with httpx. This change preserves the library's default timeout behavior by only passing the timeout argument when it is explicitly set, enhancing request management and flexibility.
This commit is contained in:
L1nSn0w
2026-02-14 14:23:02 +08:00
parent 734d52c643
commit 2020669cb0

View File

@ -56,7 +56,14 @@ class BaseRequest:
logger.debug("Failed to generate traceparent header", exc_info=True)
with httpx.Client(mounts=mounts) as client:
response = client.request(method, url, json=json, params=params, headers=headers, timeout=timeout)
# IMPORTANT:
# - In httpx, passing timeout=None disables timeouts (infinite) and overrides the library default.
# - To preserve httpx's default timeout behavior for existing call sites, only pass the kwarg when set.
request_kwargs: dict[str, Any] = {"json": json, "params": params, "headers": headers}
if timeout is not None:
request_kwargs["timeout"] = timeout
response = client.request(method, url, **request_kwargs)
if raise_for_status:
response.raise_for_status()
return response.json()