GitHub

HttpClientResponse

API reference for HttpClientResponse.

A response to request. Body reads fail with an HttpClientError whose reason is a DecodeError (or an EmptyBodyError for a stream of no body).

Attributes

AttributeTypeDescription
request= request
status= status
headers= headers
urlstr

Where the response came from, without a fragment.

remote_addressstr | None
cookiesCookies
bytes_Effect[bytes, HttpClientError]

The whole body, read once (Effect's arrayBuffer).

textEffect[str, HttpClientError]

The body as UTF-8 (invalid bytes become U+FFFD; a leading BOM is dropped).

jsonEffect[Json, HttpClientError]

The body parsed as JSON; an empty body is None.

url_params_bodyEffect[UrlParams, HttpClientError]
streamStream[bytes, HttpClientError]

The body as it arrives. No body fails with an EmptyBodyError.

upgradeEffect[SocketService, HttpClientError]

The connection of a 101 Switching Protocols response as a socket (ask for one with HttpClientRequest.upgrade). Bytes the server sent after the response head come first on the reader; releasing the reader's scope closes the connection, releasing the writer's half-closes it. Any other status fails with a StatusCodeError, so a refusal's body can still be read.

Functions

__init__

__init__(request, status, headers, body, *, url=None, set_cookie=(), remote_address=None, upgrade=None) -> None
ParameterTypeDescription
requestHttpClientRequest
statusint
headersHeaders
bodyResponseBody
urlstr | None = None
set_cookieSequence[str] = ()
remote_addressstr | None = None
upgradeEffect[SocketService, HttpClientError] | None = None
def __init__(
    self,
    request: HttpClientRequest,
    status: int,
    headers: Headers,
    body: ResponseBody,
    *,
    url: str | None = None,
    set_cookie: Sequence[str] = (),
    remote_address: str | None = None,
    upgrade: Effect[SocketService, HttpClientError] | None = None,
) -> None:
    self.request = request
    self.status = status
    self.headers = headers
    self._body = body
    self._url = url
    self._set_cookie = tuple(set_cookie)
    self._remote_address = remote_address
    self._upgrade = upgrade
    self._bytes: Effect[bytes, HttpClientError] | None = None
    self._abort_request: Callable[[], None] | None = None
    self._redacted_names: tuple[Pattern, ...] = ()

to_json

to_json() -> dict[str, object]

Returns dict[str, object]

def to_json(self) -> dict[str, object]:
    return {
        "_id": "HttpClientResponse",
        "request": self.request.to_json(),
        "status": self.status,
        "headers": self.headers.to_json(),
        "remote_address": self.remote_address,
    }