mokr.network.request ==================== .. py:module:: mokr.network.request Attributes ---------- .. autoapisummary:: mokr.network.request.LOGGER Classes ------- .. autoapisummary:: mokr.network.request.Request Module Contents --------------- .. py:data:: LOGGER .. py:class:: Request(page: mokr.browser.page.Page, client: mokr.connection.DevtoolsConnection, request_id: str | None, interception_id: str | None, is_navigation_request: bool, allow_interception: bool, url: str, resource_type: str, payload: dict, frame: mokr.frame.Frame | None, redirect_chain: list[Request], interception_callback_chain: list[Callable], httpx_request: httpx.Request | None = None) Representative of a remote network request, this object is created by a `mokr.network.NetworkManager`. The creation of a `Request` does not signify the request has been sent, or that a request response has been received. :param page: Parent `mokr.browser.Page`. :type page: Page :param client: A `mokr.connection.DevtoolsConnection` spawned by the parent `mokr.network.NetworkManager`. :type client: DevtoolsConnection :param request_id: The network request identifier, from the remote request event's requestId. :type request_id: str | None :param interception_id: The fetch request identifier, from the remote request event's interceptionId. This can be confusing as the fetch domain refers to this as the requestId. :type interception_id: str | None :param is_navigation_request: Whether or not this request will affect remote frame navigation. :type is_navigation_request: bool :param allow_interception: Whether or not to allow "request" event interception. :type allow_interception: bool :param url: The remote request URL. :type url: str :param resource_type: Resource type as it was perceived by the rendering engine. See `Request.resource_type` for more. :type resource_type: str :param payload: Request data and metadata. :type payload: dict :param frame: The `mokr.frame.Frame` this request originated from. :type frame: Frame | None :param redirect_chain: A list of `Request` objects that were redirects and lead to this request. :type redirect_chain: list[Request] :param interception_callback_chain: A list of callbacks shared with the parent `mokr.network.NetworkManager` and its parent `mokr.browser.Page`. These callbacks wil run sequentially during "request" event interception. See `mokr.browser.Page` for more information. :type interception_callback_chain: list[Callable] :param httpx_request: (httpx.Request | None, optional): If created by a `mokr.network.HttpDomain`, the original `httpx.Request` that this will be built from. .. py:property:: url :type: str URL from the remote request. .. py:property:: resource_type :type: str Resource type as it was perceived by the rendering engine. One of "Document", "Stylesheet", "Image", "Media", "Font", "Script", "TextTrack", "XHR", "Fetch", "Prefetch", "EventSource", "WebSocket", "Manifest", "SignedExchange", "Ping", "CSPViolationReport", "Preflight", or "Other". .. py:property:: method :type: str | None HTTP request method from remote request, such as "GET", "POST", "PATCH". .. py:property:: post_data :type: str | None Data from this `Request`'s `payload["postData"]`, if any. .. py:property:: headers :type: dict All headers for the target request with keys lowered. .. py:property:: response :type: mokr.network.response.Response | None The `mokr.network.Response` object created from the remote response bound to the remote request, or None if not yet received. .. py:property:: frame :type: mokr.frame.Frame | None The corresponding `mokr.frame.Frame`, if any. .. py:property:: redirect_chain :type: list[Request] Return the chain of `Request` objects if the first remote request was a redirect. The chain will be shared will all subsequent `Request` objects initiated from the redirect, and the final `Request` in the chain will not be a redirect. .. py:property:: httpx_request :type: bool If created by a `mokr.network.HttpDomain`, this will hold the original `httpx.Request` object this was populated from. Otherwise, None. .. py:method:: is_navigation_request() -> bool Whether or not this request will affect remote frame navigation. :returns: True if navigating the frame, otherwise False. :rtype: bool .. py:method:: failure_text() -> str | None Return error text from failed requests. For successful requests, this will return None. :returns: Error text if request failed, otherwise None. :rtype: str | None .. py:method:: release(url: str = None, method: str = None, post_data: str = None, headers: dict = None) -> None :async: Release an intercepted request, optionally altering select parameters. Stops execution of the rest of the interception chain. :param url: The URL to overwrite the request with, if any. Defaults to None (use initiated `Request.url`). :type url: str, optional :param method: The HTTP request method (e.g. "GET", "POST") to overwrite the request with, if any. Defaults to None (use initiated `Request.url`). :type method: str, optional :param post_data: The post data (payload["postData"]) to overwrite the request with, if any. Defaults to None (use initiated `Request.post_data`). :type post_data: str, optional :param headers: Headers, will completely replace existing headers. Defaults to None (use `Request.headers`). :type headers: dict, optional .. py:method:: fulfill(response: mokr.network.response.Response | None = None, status: int = 200, headers: dict | None = None, body: str | bytes | None = None) -> None :async: Respond to a request with the given response data. Prevents the remote request from being actually sent. Cannot be used with data urls. Stops execution of the rest of the interception chain. :param response: A completed `mokr.network.Reponse` object to extract data from. Passing this will ignore all other kwargs passed. Defaults to None. :type response: Response | None, optional :param status: HTTP status code. Defaults to 200. :type status: int, optional :param headers: Response headers. Defaults to None (empty headers). :type headers: dict | None, optional :param body: Response body. Defaults to None (empty body). :type body: str | bytes | None, optional .. py:method:: abort(error_reason: str = 'failed') -> None :async: Abort the remote request. This will prevent the request from being sent, which can cause a `mokr.exceptions.PageError` to raise later if `Request.is_navigation_request` is True. Stops execution of the rest of the interception chain. :param error_reason: The error reason to give when aborting the request. One of "Failed", "Aborted", "TimedOut", "AccessDenied", "ConnectionClosed", "ConnectionReset", "ConnectionRefused", "ConnectionAborted", "ConnectionFailed", "NameNotResolved", "InternetDisconnected", "AddressUnreachable", "BlockedByClient", or "BlockedByResponse". Defaults to "failed". :type error_reason: str, optional :raises NetworkError: Raised if unknown error reason is given.