PrefetchParameters.Builder


class PrefetchParameters.Builder


A builder class for constructing PrefetchParameters instances.

Summary

Public constructors

Construct a new Builder.

Public functions

PrefetchParameters.Builder

Sets the header value for the given key.

PrefetchParameters.Builder

Sets multiple headers at once.

PrefetchParameters

Build the PrefetchParameters.

PrefetchParameters.Builder

Sets the No-Vary-Search data that's expected to be returned via the header in the prefetch's response.

PrefetchParameters.Builder

Set whether the page that is loaded will have JavaScript enabled.

PrefetchParameters.Builder

Sets an optional variations ID to associate with this prefetch request.

Public constructors

Builder

Builder()

Construct a new Builder.

Public functions

addAdditionalHeader

@Profile.ExperimentalUrlPrefetch
fun addAdditionalHeader(key: String, value: String): PrefetchParameters.Builder

Sets the header value for the given key. If called multiple times for the same key, the last value will be used.

Header keys must be RFC 2616 compliant.

The logic for handling additional header isn't guaranteed to match the loadUrl's logic and is subject to change in the future.

Parameters
key: String

The header key.

value: String

The header value.

Returns
PrefetchParameters.Builder

This builder instance for chaining.

addAdditionalHeaders

@Profile.ExperimentalUrlPrefetch
fun addAdditionalHeaders(additionalHeaders: (Mutable)Map<String!, String!>): PrefetchParameters.Builder

Sets multiple headers at once. The headers passed in here will be merged with any that have been previously set (duplicate keys will be overridden).

Header keys must be RFC 2616 -compliant.

Parameters
additionalHeaders: (Mutable)Map<String!, String!>

A map of additional headers to set.

Returns
PrefetchParameters.Builder

This builder instance for chaining.

setExpectedNoVarySearchData

@Profile.ExperimentalUrlPrefetch
fun setExpectedNoVarySearchData(
    expectedNoVarySearchHeader: NoVarySearchHeader
): PrefetchParameters.Builder

Sets the No-Vary-Search data that's expected to be returned via the header in the prefetch's response.

This is used to help determine if WebView#loadUrl should either use an in-flight prefetch response to render the web contents or handle the URL as it typically does (i.e. start a network request).

Parameters
expectedNoVarySearchHeader: NoVarySearchHeader

The No-Vary-Search data expected to be returned in the prefetch's response.

Returns
PrefetchParameters.Builder

This builder instance for chaining.

setJavaScriptEnabled

@Profile.ExperimentalUrlPrefetch
fun setJavaScriptEnabled(javaScriptEnabled: Boolean): PrefetchParameters.Builder

Set whether the page that is loaded will have JavaScript enabled. true if the WebView's that will be loading the prefetched response will have javascript enabled. This affects whether client hints header is sent with the prefetch request.

Parameters
javaScriptEnabled: Boolean

true if the WebView that will be loading the prefetched response will have JavaScript enabled.

Returns
PrefetchParameters.Builder

This builder instance for chaining.

setVariationsId

@Profile.ExperimentalUrlPrefetch
fun setVariationsId(variationsId: Int?): PrefetchParameters.Builder

Sets an optional variations ID to associate with this prefetch request.

Parameters
variationsId: Int?

An Integer ID for this prefetch configuration, or null if no specific variations ID is applicable.

Returns
PrefetchParameters.Builder

This builder instance for chaining.