FetchInterception

Base class to wait for a Fetch response matching a URL pattern. Use this to collect and decode a paused fetch response, while keeping the use block clean and returning its own result.

Parameters

urlPattern

The URL pattern to match requests and responses.

requestStage

The stage of the fetch request to intercept (e.g., request or response).

resourceType

The type of resource to intercept (e.g., document, script, etc.).

Inheritors

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
abstract val urlPattern: String

Functions

Link copied to clipboard
abstract suspend fun continueRequest(url: String? = null, method: String? = null, postData: String? = null, headers: List<Fetch.HeaderEntry>? = null, interceptResponse: Boolean? = null)

Continues the request, optionally modifying some of its parameters.

Link copied to clipboard
abstract suspend fun continueResponse(responseCode: Int? = null, responsePhrase: String? = null, responseHeaders: List<Fetch.HeaderEntry>? = null, binaryResponseHeaders: String? = null)

Continues loading of the paused response, optionally modifying the response headers. If either responseCode or headers are modified, all of them must be present.

Link copied to clipboard
abstract suspend fun failRequest(errorReason: Network.ErrorReason)

Causes the request to fail with specified reason.

Link copied to clipboard
abstract suspend fun fulfillRequest(responseCode: Int, responseHeaders: List<Fetch.HeaderEntry>? = null, binaryResponseHeaders: String? = null, body: String? = null, responsePhrase: String? = null)

Provides response to the request.

Link copied to clipboard
abstract suspend fun getRawResponseBody(): EncodedBody

Fetches the raw response body once it has been received.

Link copied to clipboard

Returns the request event once it has been received.

Link copied to clipboard
inline suspend fun <T> FetchInterception.getResponseBody(): T

Fetches the response body once it has been received.

Link copied to clipboard
abstract suspend fun <R> use(block: suspend FetchInterception.() -> R): R

Start intercepting fetch responses matching the pattern, run block, and clean up after.