mokr.network.response

Module Contents

Classes

Response

Reprentation of a remote response to a network request. Response

Attributes

LOGGER

mokr.network.response.LOGGER
class mokr.network.response.Response(client: mokr.connection.DevtoolsConnection, request: mokr.network.request.Request, status: int, headers: dict[str, str], from_disk_cache: bool, from_service_worker: bool, from_firefox: bool, security_details: dict = None, extra_info: dict = None, httpx_response: httpx.Response | None = None)

Reprentation of a remote response to a network request. Response objects are created by the mokr.network.NetworkManager when a response or redirect response is received.

Pseudo Response objects are also made from httpx.Response objects by a mokr.network.HttpDomain.

Parameters:
  • client (DevtoolsConnection) – A mokr.connection.DevtoolsConnection spawned by the parent mokr.network.NetworkManager.

  • request (Request) – The mokr.request.Request that this Response is bound to. Importantly, the Request does not spawn this.

  • status (int) – Status code for the response.

  • headers (dict[str, str]) – Response headers as dictionary.

  • from_disk_cache (bool) – Whether the remote response was served from the cache or not.

  • from_service_worker (bool) – Whether the remote response was served by a service worker or not.

  • security_details (dict, optional) – Security information for a given response. Defaults to None.

  • extra_info (dict, optional) – Any extra info associated with the remote response. Defaults to None.

  • httpx_response – (httpx.Response | None, optional): If created by a mokr.network.HttpDomain, the original httpx.Response that this will be built from.

property url: str

URL from the remote response.

property ok: bool

Whether the response failed or not (status code between 399 and 600).

property status: int

The HTTP status code for the remote response.

property extra_status_info: str | None

Additional status information from an event’s “extraInfo” or None.

property reason: str

The HTTP reason text for the remote response.

property headers: dict

All headers for the target response with keys lowered.

property security_details: mokr.network.security.SecurityDetails | None

Initialised mokr.network.SecurityDetails if the remote response was securely received, otherwise None.

property request: mokr.network.request.Request

The mokr.network.Request object bound to this Response.

property from_cache: bool

Whether the remote response was served from the disk or memory caches.

property from_service_worker: bool

Whether the remote response was served by a service worker or not.

property httpx_response: bool

If created by a mokr.network.HttpDomain, this will hold the original httpx.Response object this was populated from. Otherwise, None.

buffer(force: bool = False) Awaitable[bytes]

Return buffer awaitable which queries remote response object’s body, if not already loaded in this Response. Can force querying with the force option.

Parameters:

force (bool, optional) – Whether to bypass checking if the body has been cached here. Useful for mokr.network.FetchDomain requests or other requests where the body may resolve slower. Defaults to False.

Returns:

Awaitable that yields response body as bytes.

Return type:

Awaitable[bytes]

async content() str | bytes

Get body of the remote response object.

If content is empty, tries to rerun query for the remote response object’s body via Response.buffer(force=True).

Returns:

Content of response.

Return type:

str | bytes

async json() dict

Load the body via json.loads.

Raises:

JSONDecodeError – Raised from json.loads if body is not JSON text.

Returns:

Loaded body as dictionary.

Return type:

dict

async to_dict() dict

Return a dictionary representation of the Response including the Response.status, Response.headers, and the response body via Response.content.

Returns:

_description_

Return type:

dict