mokr.network.request
Module Contents
Classes
Representative of a remote network request, this object is created |
Attributes
- mokr.network.request.LOGGER
- class mokr.network.request.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
Requestdoes not signify the request has been sent, or that a request response has been received.- Parameters:
page (Page) – Parent
mokr.browser.Page.client (DevtoolsConnection) – A
mokr.connection.DevtoolsConnectionspawned by the parentmokr.network.NetworkManager.request_id (str | None) – The network request identifier, from the remote request event’s requestId.
interception_id (str | None) – 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.
is_navigation_request (bool) – Whether or not this request will affect remote frame navigation.
allow_interception (bool) – Whether or not to allow “request” event interception.
url (str) – The remote request URL.
resource_type (str) – Resource type as it was perceived by the rendering engine. See
Request.resource_typefor more.payload (dict) – Request data and metadata.
frame (Frame | None) – The
mokr.frame.Framethis request originated from.redirect_chain (list[Request]) – A list of
Requestobjects that were redirects and lead to this request.interception_callback_chain (list[Callable]) – A list of callbacks shared with the parent
mokr.network.NetworkManagerand its parentmokr.browser.Page. These callbacks wil run sequentially during “request” event interception. Seemokr.browser.Pagefor more information.httpx_request – (httpx.Request | None, optional): If created by a
mokr.network.HttpDomain, the originalhttpx.Requestthat this will be built from.
- property url: str
URL from the remote request.
- property resource_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”.
- property method: str | None
HTTP request method from remote request, such as “GET”, “POST”, “PATCH”.
- property post_data: str | None
Data from this
Request’spayload["postData"], if any.
- property headers: dict
All headers for the target request with keys lowered.
- property response: mokr.network.response.Response | None
The
mokr.network.Responseobject created from the remote response bound to the remote request, or None if not yet received.
- property frame: mokr.frame.Frame | None
The corresponding
mokr.frame.Frame, if any.
- property redirect_chain: list[Request]
Return the chain of
Requestobjects if the first remote request was a redirect.The chain will be shared will all subsequent
Requestobjects initiated from the redirect, and the finalRequestin the chain will not be a redirect.
- property httpx_request: bool
If created by a
mokr.network.HttpDomain, this will hold the originalhttpx.Requestobject this was populated from. Otherwise, None.
Whether or not this request will affect remote frame navigation.
- Returns:
True if navigating the frame, otherwise False.
- Return type:
bool
- 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.
- Return type:
str | None
- async release(url: str = None, method: str = None, post_data: str = None, headers: dict = None) None
Release an intercepted request, optionally altering select parameters.
Stops execution of the rest of the interception chain.
- Parameters:
url (str, optional) – The URL to overwrite the request with, if any. Defaults to None (use initiated
Request.url).method (str, optional) – The HTTP request method (e.g. “GET”, “POST”) to overwrite the request with, if any. Defaults to None (use initiated
Request.url).post_data (str, optional) – The post data (payload[“postData”]) to overwrite the request with, if any. Defaults to None (use initiated
Request.post_data).headers (dict, optional) – Headers, will completely replace existing headers. Defaults to None (use
Request.headers).
- async fulfill(response: mokr.network.response.Response | None = None, status: int = 200, headers: dict | None = None, body: str | bytes | None = None) None
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.
- Parameters:
response (Response | None, optional) – A completed
mokr.network.Reponseobject to extract data from. Passing this will ignore all other kwargs passed. Defaults to None.status (int, optional) – HTTP status code. Defaults to 200.
headers (dict | None, optional) – Response headers. Defaults to None (empty headers).
body (str | bytes | None, optional) – Response body. Defaults to None (empty body).
- async abort(error_reason: str = 'failed') None
Abort the remote request. This will prevent the request from being sent, which can cause a
mokr.exceptions.PageErrorto raise later ifRequest.is_navigation_requestis True.Stops execution of the rest of the interception chain.
- Parameters:
error_reason (str, optional) – 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”.
- Raises:
NetworkError – Raised if unknown error reason is given.