mokr.network
Submodules
Classes
This class manages a collection of dictionaries used by |
|
Client to handle sending manual fetch requests. |
|
Client to handle sending requests outside of the browser, while syncing |
|
The base event emitter class. All other event emitters inherit from |
|
Class to handle requests in a given |
|
Class to handle requests in a given |
|
Representative of a remote network request, this object is created |
|
Reprentation of a remote response to a network request. |
|
A simple representation of remote response security details. |
Package Contents
- class mokr.network.NetworkEventManager
This class manages a collection of dictionaries used by
mokr.network.NetworkManagerto track active event status as events can be received in multiple different orders.See
mokr.network.NetworkManagerfor more information.- request_will_be_sent_map
- request_paused_map
- http_requests_map
- response_received_extra_info_map
- queued_redirect_info_map
- queued_event_group_map
- forget(network_id: str) None
Remove data for the given
network_idfrom all mappings.- Parameters:
network_id (str) – Request network identifier.
- response_extra_info(network_id: str) list[dict]
Get stored response extraInfo for given
network_id.- Parameters:
network_id (str) – Request network identifier.
- Returns:
List of extraInfo events as dictionaries.
- Return type:
list[dict]
- queued_redirect_info(fetch_id: str) list[dict]
Get stored redirect info for given
fetch_id.- Parameters:
fetch_id (str) – Request fetch identifier.
- Returns:
List of redirect info as dictionaries.
- Return type:
list[dict]
- queue_redirect_info(fetch_id: str, redirect_info: list[dict]) None
Store redirect info under a given
fetch_id.- Parameters:
fetch_id (str) – Request fetch identifier.
redirect_info (list[dict]) – Redirect info data.
- take_queued_redirect_info(fetch_id: str) list[dict]
Remove and return redirect info stored under given
fetch_id.- Parameters:
fetch_id (str) – Request fetch identifier.
- Returns:
Redirect info data.
- Return type:
list[dict]
- get_in_flight_requests_count() int
Get the number of active requests (not resolved).
- Returns:
Number of active requests.
- Return type:
int
- store_request_will_be_sent(network_id: str, event: dict) None
Store a requestWillBeSent event under given
network_id.- Parameters:
network_id (str) – Request network identifier.
event (dict) – The requestWillBeSent event received.
- get_request_will_be_sent(network_id: str) dict
Get requestWillBeSent event stored under given
network_id.- Parameters:
network_id (str) – Request network identifier.
- Returns:
The stored requestWillBeSent under given
network_id.- Return type:
dict
- forget_request_will_be_sent(network_id: str) None
Remove requestWillBeSent stored under given
network_id.- Parameters:
network_id (str) – Request network identifier.
- get_request_paused(network_id: str) dict
Get requestPaused event stored under given
network_id.- Parameters:
network_id (str) – Request network identifier.
- Returns:
The stored requestPaused under given
network_id.- Return type:
dict
- forget_request_paused(network_id: str) None
Remove requestPaused stored under given
network_id.- Parameters:
network_id (str) – Request network identifier.
- store_request_paused(network_id: str, event: dict) None
Store a requestPaused event under given
network_id.- Parameters:
network_id (str) – Request network identifier.
event (dict) – The requestPaused event received.
- get_request(network_id: str) mokr.network.request.Request
Get
mokr.network.Requeststored under givennetwork_id.- Parameters:
network_id (str) – Request network identifier.
- Returns:
The stored
mokr.network.Requestunder givennetwork_id.- Return type:
dict
- store_request(network_id: str, request: mokr.network.request.Request) None
Store a
mokr.network.Requestunder givennetwork_id.- Parameters:
network_id (str) – Request network identifier.
request (Request) – The
mokr.network.Requestreceived.
- forget_request(network_id: str) None
Remove
mokr.network.Requeststored under givennetwork_id.- Parameters:
network_id (str) – Request network identifier.
- get_queued_event_group(network_id: str) dict
Get responseReceivedEvent event stored under given
network_id.- Parameters:
network_id (str) – Request network identifier.
- Returns:
- The stored responseReceivedEvent event under given
network_id.
- Return type:
dict
- queue_event_group(network_id: str, event: dict) None
Store a responseReceivedEvent event under given
network_id.- Parameters:
network_id (str) – Request network identifier.
event (dict) – The responseReceivedEvent received.
- forget_queued_event_group(network_id: str) None
Remove responseReceivedEvent event stored under given
network_id.- Parameters:
network_id (str) – Request network identifier.
- class mokr.network.FetchDomain(page: mokr.browser.page.Page)
Bases:
pyee.EventEmitterClient to handle sending manual fetch requests.
Note that sending fetch requests from this class will temporarily enable request interception globally. However, these fetch requests won’t be caught by the request interception chain, however “response” and “requestfinished” events will still be caught.
For Firefox this is not applicable. Fetch requests in Firefox are built manually from the response data. Unlike standard Firefox request responses, the response body is available for
FetchDomainresponses.Chrome requests take advantage of the existing fetch system in its
mokr.network.NetworkManagerwhile Firefox cannot; Chrome could do the same as Firefox does here and build the objects directly but some features would be lost like redirect chain.- Parameters:
page (Page) – Parent
mokr.browser.Pagethis was spawned from.
- async fetch(url: str | None = None, timeout: int = None, request: mokr.network.request.Request | None = None, body: str | None = None, browsing_topics: bool | None = None, cache: mokr.constants.HTTP_CACHE_TYPES | None = None, credentials: Literal['omit', 'same-origin', 'include'] | None = None, headers: dict | None = None, method: mokr.constants.HTTP_METHODS = 'GET', mode: Literal['cors', 'no-cors', 'same-origin'] = None, priority: Literal['high', 'low', 'auto'] | None = None, redirect: Literal['follow', 'error', 'manual'] | None = None, referrer: str | None = None, referrer_policy: mokr.constants.REFERRER_POLICIES | None = None) mokr.network.response.Response
Send a fetch request.
Note that fetch is sensitive to the current site’s CORS settings. Additionally, trying to send a fetch request before the DOM loads can hang forever.
- Parameters:
url (str | None, optional) – The url to request. Ignored if
requestis given. Defaults to None.timeout (int, optional) – Time in milliseconds to wait. Defaults to None.
request (Request | None, optional) – A request object to pull
url,method, andheadersfrom. Defaults to None.body (str | None, optional) – Body to add to the request. Defaults to None.
browsing_topics (bool | None, optional) – If True, selected topics will be sent in a Sec-Browsing-Topics header with the associated request. Defaults to None.
cache (HTTP_CACHE_TYPES) – How the request should interact with the HTTP cache. One of: “default”, “no-store”, “reload”, “no-cache”, “force-cache”, or “only-if-cache”. Defaults to None.
credentials (Literal[str] | None, optional) – How to handle credentials. One of “omit”, “same-origin”, or “include”. Defaults to None.
headers (dict | None, optional) – Headers to pass with the request. Defaults to None.
method (HTTP_METHODS, optional) – HTTP method. Defaults to “GET”.
mode (Literal["cors", "no-cors", "same-origin"], optional) – CORS mode to use. Defaults to None.
priority (Literal["high", "low", "auto"] | None, optional) – Priority of request relative to others. Defaults to None.
redirect (Literal["follow", "error", "manual"] | None, optional) – How to handle redirects. Defaults to None (“follow”).
referrer (str | None, optional) – Request referrer. Defaults to None.
referrer_policy (REFERRER_POLICIES) – The referrer policy to use. One of “no-referrer”, “no-referrer-when-downgrade”, “same-origin”, “origin”, “strict-origin”, “origin-when-cross-origin”, “strict-origin-when-cross-origin”, or “unsafe-url”. Defaults to None (“strict-origin-when-cross-origin”).
- Raises:
ValueError – Raised if neither
urlnorrequestgiven.NetworkError – Raised if no response found when request resolves.
- Returns:
Last response recieved after all redirects, if any.
- Return type:
- class mokr.network.HttpDomain(page: mokr.browser.page.Page, sync_cookies: Literal['both', 'http', 'page', 'none'] = 'both', **httpx_client_kwargs)
Client to handle sending requests outside of the browser, while syncing state between itself and the parent
mokr.browser.Page.This client uses
httpxso requests can be made with HTTP2.- Parameters:
page (Page) – Parent
mokr.browser.Pagethat this will sync with.sync_cookies (Literal["both", "http", "page", "none"], optional) – Whether to sync cookies between this client and the parent
mokr.browser.Pagebefore/after each request and response. Defaults to “both”.
- async send(url: str, method: mokr.constants.HTTP_METHODS = 'GET', params: dict | None = None, headers: dict | None = None, data: dict | None = None, json: dict | None = None, **httpx_request_kwargs) mokr.network.response.Response
Send an HTTP request.
- Parameters:
url (str) – The url to request.
method (Literal[str], optional) – HTTP method. Defaults to “GET”.
params (dict | None, optional) – Parameters to encode in the URL before sending. Defaults to None (omitted).
headers (dict | None, optional) – Additional headers to send with this request beyond what was set when the client was created. Defaults to None (omitted).
data (dict | None, optional) – Data payload to deliver with request (form-encoded data). Only for “PUT”, “POST”, and “PATCH”. Defaults to None (omitted).
json (dict | None, optional) – Data payload to deliver with request (JSON-encoded data). Only for “PUT”, “POST”, and “PATCH”. Defaults to None (omitted).
- Raises:
ValueError – Raised if invalid HTTP method given or
dataorjsonarguments given with incompatible methods.- Returns:
- A
mokr.network.Responsecreated from the httpx.Response. All redirects will also be created, and original requests and responses will be accessible from themokr.networkobjects.
- A
- Return type:
- class mokr.network.NetworkManager(page: mokr.browser.page.Page, client: mokr.connection.DevtoolsConnection, frame_manager: mokr.frame.FrameManager, interception_callback_chain: list[Callable])
Bases:
pyee.EventEmitterThe base event emitter class. All other event emitters inherit from this class.
Most events are registered with an emitter via the
onandoncemethods, and fired with theemitmethod. However, pyee event emitters have two special events:new_listener: Fires whenever a new listener is created. Listeners for this event do not fire upon their own creation.error: When emitted raises an Exception by default, behavior can be overridden by attaching callback to the event.For example:
```py @ee.on(‘error’) def on_error(message):
logging.err(message)
ee.emit(‘error’, Exception(‘something blew up’)) ```
All callbacks are handled in a synchronous, blocking manner. As in node.js, raised exceptions are not automatically handled for you—you must catch your own exceptions, and treat them accordingly.
- credentials
- user_agent = ''
- user_agent_metadata = ''
- classmethod create(page: mokr.browser.page.Page, client: mokr.connection.DevtoolsConnection, frame_manager: mokr.frame.FrameManager, ignore_https_errors: bool, interception_callback_chain: list[Callable]) NetworkManager
- Async:
Async constructor for this class. Necessary to run some asyncronous post-initialisation tasks.
- Parameters:
page (Page) – Parent
mokr.browser.Page.client (DevtoolsConnection) – A
mokr.connection.DevtoolsConnectionspawned by the parentmokr.browser.Page.frame_manager (FrameManager) – A
mokr.frame.FrameManagerspawned by the parentmokr.browser.Page.ignore_https_errors (bool) – Ignore site security errors. Inherited from parent
mokr.browser.Page.interception_callback_chain (list[Callable]) – A list of callables for use with “request” event interception. This list is shared by the parent
mokr.browser.Pageand all newly createdmokr.network.Requestobjects in this manager.
- Returns:
New
NetworkManagerwith applied configurations.- Return type:
- abstract set_extra_http_headers() None
- Async:
- abstract set_request_interception() None
- Async:
- abstract set_credentials() None
- Async:
- async emulate_network_conditions(latency: int | None = 0, download: int | None = -1, upload: int | None = -1) None
Emulate the given network conditions. If network conditions unset, will set them to the default (disable all throttling and no latency).
- Parameters:
latency (int, optional) – Minimum latency in milliseconds from request sent to response headers received. Defaults to None (0).
download (int, optional) – Maximum download throughput (bytes/sec). Defaults to None (-1, disabled).
upload (int, optional) – Minimum download throughput (bytes/sec). Defaults to None (-1, disabled).
- async set_offline_mode(choice: bool) None
Enable or diable offline mode. Disabled by default.
- Parameters:
enabled (bool) – False to disable, True to enable.
- async set_request_cache(enabled: bool) None
Enable or disable request caching. Request caching caches requests in the browser, not
mokr.network.Requestobjects.Does not check if request caching was enabled already by parent
mokr.browser.Page.- Parameters:
enabled (bool, optional) – True to enable, False to disable. Defaults to True.
- async set_user_agent(user_agent: str, user_agent_metadata: str | None = None) None
Update the user agent to be sent with every request.
- Parameters:
user_agent (str) – User agent string.
user_agent_metadata (str | None, optional) – Experimental, used to specify user agent client hints to emulate.
- class mokr.network.ChromeNetworkManager(page: mokr.browser.page.Page, client: mokr.connection.DevtoolsConnection, frame_manager: mokr.frame.FrameManager, interception_callback_chain: list[Callable])
Bases:
mokr.network.manager.base.NetworkManagerClass to handle requests in a given
mokr.browser.Page.This class relies on network events to be emitted, and stores events and even requests to handle the various possible chains of events.
The
interception_callback_chainthis class receives from the parentmokr.browser.Pageis shared with spawnedmokr.network.Requestobjects. While the request interception callback chain is run from theRequestobject, it is initiated during select events from this class.There are four possible orders that requests will be triggered and thus handled by
NetworkManager:_on_request_will_be_sent._on_request_will_be_sent,_on_request_paused._on_request_paused,_on_request_will_be_sent._on_request_paused,_on_request_will_be_sent,_on_request_paused,_on_request_will_be_sent,_on_request_paused,_on_request_paused(see crbug.com/1196004).
There are a few different ways requests need to be handled due to this: - For
_on_requestwe need the event from_on_request_will_be_sentand optionally thefetch_request_id(event[“requestId”] also known as “interceptionId”) from_on_request_paused. - If request interception is disabled, call_on_requestonce per call to_on_request_will_be_sent. - If request interception is enabled, call_on_requestonce per call to_on_request_paused(once perfetch_request_id). - Events are stored via themokr.network.NetworkEventManagerto allow for subsequent events to call_on_request. - Chains of redirect requests have the samerequestIdas the original request. This means events can be received in multiple orders for different requests in the same redirect chain such as:_on_request_will_be_sent,_on_request_will_be_sent, …_on_request_will_be_sent,_on_request_paused,_on_request_will_be_sent,_on_request_paused, …
_on_request_will_be_sent,_on_request_paused,_on_request_paused,_on_request_will_be_sent, …
_on_request_paused,_on_request_will_be_sent,_on_request_paused,_on_request_will_be_sent,_on_request_paused,_on_request_will_be_sent,_on_request_paused,_on_request_paused, … (see crbug.com/1196004)
- Parameters:
page (Page) – Parent
mokr.browser.Page.client (DevtoolsConnection) – A
mokr.connection.DevtoolsConnectionspawned by the parentmokr.browser.Page.frame_manager (FrameManager) – The
mokr.frame.FrameManagerfrom themokr.browser.Pagethat spawned this element.interception_callback_chain (list[Callable]) – A list of callbacks to be passed into new
mokr.network.Request`s that will be run during "request" event interception, by that object. Inherited from the parent `mokr.browser.Page.
- property extra_http_headers: dict[str, str]
Any extra HTTP headers assigned to this class. These are sent with every request this manager handles.
- forget_request(request: mokr.network.request.Request, events: bool) None
Drop a request from the
mokr.network.NetworkEventManagerand remove from attempted authentications listing, if relevant.Optionally forget all events tied to the remote request networkID, too.
- Parameters:
request (Request) –
mokr.request.Requestto forget.events (bool) – If True, drop all events stored for the request, too.
- get_in_flight_requests_count() int
Get the number of active requests (not resolved). Wraps
mokr.network.NetworkEventManager.get_in_flight_requests_count.- Returns:
Number of active requests.
- Return type:
int
- async set_credentials(credentials: dict[Literal['username', 'password'], str]) None
Set the credentials to use for HTTP authentication.
- Parameters:
credentials (dict[str, str]) – A dictionary with credentials, keyed as “username” and “password”.
- async set_extra_http_headers(extra_http_headers: dict[str, str]) None
Set extra headers to be sent with every request.
- Parameters:
extra_http_headers (dict[str, str]) – A dictionary of headers.
- Raises:
ValueError – Raised if any header value is not string.
- async set_request_interception(choice: bool) None
Disable or enabled request interception (enabled by default). See
mokr.browser.Page.onfor details on using the request interception callback chain.- Parameters:
choice (bool) – False to disable, True to enable.
- class mokr.network.FirefoxNetworkManager(page: mokr.browser.page.Page, client: mokr.connection.DevtoolsConnection, frame_manager: mokr.frame.FrameManager, interception_callback_chain: list[Callable])
Bases:
mokr.network.manager.base.NetworkManagerClass to handle requests in a given
mokr.browser.Page.Note that functionality of this class is severely limited compared to it’s Chrome counterpart,
mokr.network.ChromeNetworkManager.Request interception does not block requests and can only be used to observe partial request and response data.
The
interception_callback_chainthis class receives from the parentmokr.browser.Pageis shared with spawnedmokr.network.Requestobjects. While the request interception callback chain is run from theRequestobject, it is initiated during select events from this class.- Parameters:
page (Page) – Parent
mokr.browser.Page.client (DevtoolsConnection) – A
mokr.connection.DevtoolsConnectionspawned by the parentmokr.browser.Page.frame_manager (FrameManager) – The
mokr.frame.FrameManagerfrom themokr.browser.Pagethat spawned this element.interception_callback_chain (list[Callable]) – A list of callbacks to be passed into new
mokr.network.Request`s that will be run during "request" event interception, by that object. Inherited from the parent `mokr.browser.Page.
- property extra_http_headers: dict[str, str]
For parity; Firefox doesn’t support sending extra headers via CDP.
- async set_request_interception(*args, **kwargs) None
Not supported by Firefox.
- Raises:
FirefoxNotImplementedError – When Firefox unsupported errors are on.
- async set_extra_http_headers(*args, **kwargs) None
Not supported by Firefox.
- Raises:
FirefoxNotImplementedError – When Firefox unsupported errors are on.
- class mokr.network.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.
- class mokr.network.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
- class mokr.network.SecurityDetails(subject_name: str, issuer: str, valid_from: int, valid_to: int, protocol: str)
A simple representation of remote response security details.
- Parameters:
subject_name (str) – Subject to which the certificate was issued to.
issuer (str) – Name of issuer of the certificate.
valid_from (int) – Unix time string of start of certificate validity.
valid_to (int) – Unix time string of end of certificate validity.
protocol (str) – Security protocol (e.g. “TLS1.2”, “TLS1.3”).
- property subject_name: str
Subject to which the certificate was issued to.
- property issuer: str
Name of issuer of the certificate.
- property valid_from: int
Unix time string of start of certificate validity.
- property valid_to: int
Unix time string of end of certificate validity.
- property protocol: str
Security protocol (e.g. “TLS1.2”, “TLS1.3”).