sinch.core.ports.http_transport module
- class sinch.core.ports.http_transport.HTTPTransport(sinch)[source]
Bases:
ABCBase class for HTTP transports.
Subclasses implement
send_request()to perform the raw HTTP call. The publicrequest()method adds cross-cutting concerns on top: request preparation, authentication, and automatic token refresh on 401.Deprecated since version 2.1: Overriding
send()(the oldsend(endpoint)hook) is still honored but deprecated; implementsend_request()instead. Thesendoverride path will be removed in 3.0.- MAX_RETRIES = 3
- RETRYABLE_STATUS_CODES = frozenset({429})
- BACKOFF_BASE_SECONDS = 1.0
- BACKOFF_GROWTH = 4
- RETRY_AFTER_JITTER = 0.25
- send_request(
- request_data: HttpRequest,
Performs a single HTTP round-trip for an already-prepared, authenticated request.
- Parameters:
request_data (HttpRequest) – The prepared request to send.
- Returns:
The HTTP response.
- Return type:
- send(
- endpoint: HTTPEndpoint,
Prepares, authenticates and performs a single round-trip for an endpoint.
Deprecated since version 2.1: This hook is deprecated. Implement
send_request()instead; thesendoverride path will be removed in 3.0.- Parameters:
endpoint (HTTPEndpoint) – The endpoint to call.
- Returns:
The HTTP response.
- Return type:
- request(
- endpoint: HTTPEndpoint,
Sends a request, renewing the token and retrying once on an expired-token 401.
- Parameters:
endpoint (HTTPEndpoint) – The endpoint to call.
- Returns:
The handled HTTP response.
- Return type:
- authenticate(
- endpoint: HTTPEndpoint,
- request_data: HttpRequest,
Stamps the credentials required by the endpoint’s auth scheme onto the request.
- Parameters:
endpoint (HTTPEndpoint) – The endpoint being called, whose HTTP_AUTHENTICATION selects the scheme.
request_data (HttpRequest) – The request to authenticate, mutated in place.
- Returns:
The same request, with auth applied.
- Return type:
- Raises:
ValidationException – If the credentials required by the scheme are missing.
- prepare_request(
- endpoint: HTTPEndpoint,
Builds the HttpRequest for an endpoint.
- Parameters:
endpoint (HTTPEndpoint) – The endpoint to build the request for.
- Returns:
The prepared request.
- Return type:
- static deserialize_json_response(response: Response) dict[source]
Parses the JSON body of a response.
- Parameters:
response (Response) – The raw HTTP response.
- Returns:
The parsed body.
- Return type:
dict
- Raises:
SinchException – If the body is present but not valid JSON.