mokr.network.response
Module Contents
Classes
Reprentation of a remote response to a network request. |
Attributes
- 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.
Responseobjects are created by themokr.network.NetworkManagerwhen a response or redirect response is received.Pseudo
Responseobjects are also made fromhttpx.Responseobjects by amokr.network.HttpDomain.- Parameters:
client (DevtoolsConnection) – A
mokr.connection.DevtoolsConnectionspawned by the parentmokr.network.NetworkManager.request (Request) – The
mokr.request.Requestthat thisResponseis bound to. Importantly, theRequestdoes 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 originalhttpx.Responsethat 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.SecurityDetailsif the remote response was securely received, otherwise None.
- property request: mokr.network.request.Request
The
mokr.network.Requestobject bound to thisResponse.
- 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 originalhttpx.Responseobject 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 theforceoption.- Parameters:
force (bool, optional) – Whether to bypass checking if the body has been cached here. Useful for
mokr.network.FetchDomainrequests 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.loadsif body is not JSON text.- Returns:
Loaded body as dictionary.
- Return type:
dict
- async to_dict() dict
Return a dictionary representation of the
Responseincluding theResponse.status,Response.headers, and the response body viaResponse.content.- Returns:
_description_
- Return type:
dict