animedex.transport.http
HTTP client wrapper used by every animedex backend.
The HttpClient composes animedex.transport.useragent,
animedex.transport.ratelimit, and a single requests.Session.
Responsibilities:
Inject the project User-Agent on every request unless the caller passes an explicit override.
Strip
Viafrom outgoing headers (MangaDex forbids it; we strip it for every backend to make the contract uniform and so a misconfigured shared proxy cannot accidentally trip the constraint).Consult the per-backend rate-limit bucket before issuing the call.
Backends should not subclass this class; they should compose it. The goal is one HTTP call site per backend so retry, timeout, redirect policy, and TLS settings live in exactly one place.
HttpClient
- class animedex.transport.http.HttpClient(*, backend: str, base_url: str, session: Session | None = None, rate_limit_registry: RateLimitRegistry | None = None, user_agent: str | None = None, timeout_seconds: float = 30.0)[source]
Bases:
objectAn HTTP client bound to a single backend.
- Parameters:
backend (str) – Backend identifier (e.g.
"anilist"); used to pick the rate-limit bucket.base_url (str) – Base URL prefix joined with the request path.
session (requests.Session or None) – Existing
requests.Sessionto reuse. Optional; one is created when not given.rate_limit_registry (RateLimitRegistry or None) – Source of the rate-limit bucket. Defaults to
animedex.transport.ratelimit.default_registry().user_agent (str or None) – Override for the User-Agent string. Defaults to
animedex.transport.useragent.default_user_agent().timeout_seconds (float) – Request timeout in seconds.
- __init__(*, backend: str, base_url: str, session: Session | None = None, rate_limit_registry: RateLimitRegistry | None = None, user_agent: str | None = None, timeout_seconds: float = 30.0) None[source]
- request(method: str, path: str, **kwargs: Any) Response[source]
Issue an HTTP request through the shared transport stack.
- Parameters:
method (str) – HTTP method (case-insensitive on input; upper-cased internally).
path (str) – Request path. Joined with
base_urlunless an absolute URL is given.kwargs – Forwarded to
requests.Session.request(), withheadersmediated by_prepare_headers()andtimeoutdefaulted totimeout_seconds.
- Returns:
The response object.
- Return type:
- Raises:
KeyError – When the rate-limit bucket rejects the backend identifier.
selftest
- animedex.transport.http.selftest() bool[source]
Smoke-test
HttpClientwithout touching the network.Verifies the constructor wires UA and the rate limiter without touching the network.
- Returns:
Trueon success.- Return type: