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
abstract val requestStage: <Error class: unknown class>

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

Link copied to clipboard
abstract val resourceType: <Error class: unknown class>

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

Link copied to clipboard
abstract val urlPattern: String

The URL pattern to match requests and responses.

Functions

Link copied to clipboard
abstract suspend fun continueRequest(url: String? = null, method: String? = null, postData: String? = null, headers: List<<Error class: unknown class>>? = 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<<Error class: unknown class>>? = 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: <Error class: unknown class>)

Causes the request to fail with specified reason.

Link copied to clipboard
abstract suspend fun fulfillRequest(responseCode: Int, responseHeaders: List<<Error class: unknown class>>? = 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
abstract suspend fun getRequest(): <Error class: unknown class>

Returns the request once it has been received.

Link copied to clipboard
abstract suspend fun getRequestEvent(): <Error class: unknown class>

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 reset()

Resets the internal state, allowing the interception to be reused.

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.