mokr.network.http

Classes

HttpDomain

Client to handle sending requests outside of the browser, while syncing

Module Contents

class mokr.network.http.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 httpx so requests can be made with HTTP2.

Parameters:
  • page (Page) – Parent mokr.browser.Page that this will sync with.

  • sync_cookies (Literal["both", "http", "page", "none"], optional) – Whether to sync cookies between this client and the parent mokr.browser.Page before/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 data or json arguments given with incompatible methods.

Returns:

A mokr.network.Response created from the

httpx.Response. All redirects will also be created, and original requests and responses will be accessible from the mokr.network objects.

Return type:

Response