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 Via from 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: object

An HTTP client bound to a single backend.

Parameters:
__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_url unless an absolute URL is given.

  • kwargs – Forwarded to requests.Session.request(), with headers mediated by _prepare_headers() and timeout defaulted to timeout_seconds.

Returns:

The response object.

Return type:

requests.Response

Raises:

KeyError – When the rate-limit bucket rejects the backend identifier.

get(path: str, **kwargs: Any) Response[source]

Issue a GET request. Convenience over request().

post(path: str, **kwargs: Any) Response[source]

Issue a POST request. Convenience over request().

Method and path are passed through verbatim; callers own the upstream result.

selftest

animedex.transport.http.selftest() bool[source]

Smoke-test HttpClient without touching the network.

Verifies the constructor wires UA and the rate limiter without touching the network.

Returns:

True on success.

Return type:

bool