mokr.network.response ===================== .. py:module:: mokr.network.response Attributes ---------- .. autoapisummary:: mokr.network.response.LOGGER Classes ------- .. autoapisummary:: mokr.network.response.Response Module Contents --------------- .. py:data:: LOGGER .. py:class:: 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`. :param client: A `mokr.connection.DevtoolsConnection` spawned by the parent `mokr.network.NetworkManager`. :type client: DevtoolsConnection :param request: The `mokr.request.Request` that this `Response` is bound to. Importantly, the `Request` does not spawn this. :type request: Request :param status: Status code for the response. :type status: int :param headers: Response headers as dictionary. :type headers: dict[str, str] :param from_disk_cache: Whether the remote response was served from the cache or not. :type from_disk_cache: bool :param from_service_worker: Whether the remote response was served by a service worker or not. :type from_service_worker: bool :param security_details: Security information for a given response. Defaults to None. :type security_details: dict, optional :param extra_info: Any extra info associated with the remote response. Defaults to None. :type extra_info: dict, optional :param httpx_response: (httpx.Response | None, optional): If created by a `mokr.network.HttpDomain`, the original `httpx.Response` that this will be built from. .. py:property:: url :type: str URL from the remote response. .. py:property:: ok :type: bool Whether the response failed or not (status code between 399 and 600). .. py:property:: status :type: int The HTTP status code for the remote response. .. py:property:: extra_status_info :type: str | None Additional status information from an event's "extraInfo" or None. .. py:property:: reason :type: str The HTTP reason text for the remote response. .. py:property:: headers :type: dict All headers for the target response with keys lowered. .. py:property:: security_details :type: mokr.network.security.SecurityDetails | None Initialised `mokr.network.SecurityDetails` if the remote response was securely received, otherwise None. .. py:property:: request :type: mokr.network.request.Request The `mokr.network.Request` object bound to this `Response`. .. py:property:: from_cache :type: bool Whether the remote response was served from the disk or memory caches. .. py:property:: from_service_worker :type: bool Whether the remote response was served by a service worker or not. .. py:property:: httpx_response :type: bool If created by a `mokr.network.HttpDomain`, this will hold the original `httpx.Response` object this was populated from. Otherwise, None. .. py:method:: 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. :param force: 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. :type force: bool, optional :returns: Awaitable that yields response body as bytes. :rtype: Awaitable[bytes] .. py:method:: content() -> str | bytes :async: 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. :rtype: str | bytes .. py:method:: json() -> dict :async: Load the body via `json.loads`. :raises JSONDecodeError: Raised from `json.loads` if body is not JSON text. :returns: Loaded body as dictionary. :rtype: dict .. py:method:: to_dict() -> dict :async: Return a dictionary representation of the `Response` including the `Response.status`, `Response.headers`, and the response body via `Response.content`. :returns: _description_ :rtype: dict