correspond.channels._http

A small HTTP client over urllib, shared by the HTTP adapters, with failures classified.

Adapters take it as http=. The call shape is http(method, url, *, headers=None, body=None, timeout=DEFAULT_TIMEOUT_S) -> Response: an HTTP error status comes back as a Response like any other, and only “could not reach the server” raises, as a ChannelError of kind network that names the host and never the URL (a URL path can carry a token). Tests pass a scripted function of the same shape.

>>> classify(429, "slow down", {"retry-after": "3"}).retry_after
3.0
>>> classify(404, "gone").kind
'not_found'
class correspond.channels._http.Response(status: int, headers: Mapping[str, str]=<factory>, body: bytes = b'')[source]

An HTTP response: status, lower-cased headers, raw body.

json() Any[source]

The body parsed as JSON, or None when it is not JSON.

correspond.channels._http.classify(status: int, message: str, headers: Mapping[str, str] | None = None) ChannelError[source]

The ChannelError an HTTP error status means.

correspond.channels._http.retry_after_seconds(headers: Mapping[str, str] | None) float | None[source]

Retry-After in seconds (it may be a number or an HTTP date), or None.

correspond.channels._http.urllib_http(method: str, url: str, *, headers: Mapping[str, str] | None = None, body: bytes | None = None, timeout: float = 30) Response[source]

One request with the standard library.