sinch.core.ports.http_transport module

class sinch.core.ports.http_transport.HTTPTransport(sinch)[source]

Bases: ABC

Base class for HTTP transports.

Subclasses implement send to perform the raw HTTP call. The public request method adds cross-cutting concerns on top: authentication, logging hooks, and automatic token refresh on 401.

abstractmethod send(
endpoint: HTTPEndpoint,
) HTTPResponse[source]

Execute a single HTTP round-trip and return the response.

Implementations must prepare the request, authenticate, perform the HTTP call, deserialize the response, and return an HTTPResponse. They should not handle token refresh — that is done by request.

Parameters:

endpoint (HTTPEndpoint)

Return type:

HTTPResponse

request(
endpoint: HTTPEndpoint,
) HTTPResponse[source]

Send a request with automatic OAuth token refresh on 401.

If the server responds with 401 and the token is detected as expired, the token is invalidated and one retry is attempted with a fresh token. A second consecutive 401 is handed straight to the endpoint’s error handler — no further retries.

Parameters:

endpoint (HTTPEndpoint)

Return type:

HTTPResponse

authenticate(endpoint, request_data)[source]
prepare_request(
endpoint: HTTPEndpoint,
) HttpRequest[source]
Parameters:

endpoint (HTTPEndpoint)

Return type:

HttpRequest

static deserialize_json_response(response)[source]