PrefetchParameters.Builder


public final class PrefetchParameters.Builder


A builder class for constructing PrefetchParameters instances.

Summary

Public constructors

Construct a new Builder.

Public methods

@NonNull PrefetchParameters.Builder

Sets the header value for the given key.

@NonNull PrefetchParameters.Builder

Sets multiple headers at once.

@NonNull PrefetchParameters

Build the PrefetchParameters.

@NonNull PrefetchParameters.Builder

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

@NonNull PrefetchParameters.Builder

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

@NonNull PrefetchParameters.Builder

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

Public constructors

Builder

public Builder()

Construct a new Builder.

Public methods

addAdditionalHeader

@Profile.ExperimentalUrlPrefetch
public @NonNull PrefetchParameters.Builder addAdditionalHeader(@NonNull String key, @NonNull String value)

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
@NonNull String key

The header key.

@NonNull String value

The header value.

Returns
@NonNull PrefetchParameters.Builder

This builder instance for chaining.

addAdditionalHeaders

@Profile.ExperimentalUrlPrefetch
public @NonNull PrefetchParameters.Builder addAdditionalHeaders(@NonNull Map<StringString> additionalHeaders)

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
@NonNull Map<StringString> additionalHeaders

A map of additional headers to set.

Returns
@NonNull PrefetchParameters.Builder

This builder instance for chaining.

setExpectedNoVarySearchData

@Profile.ExperimentalUrlPrefetch
public @NonNull PrefetchParameters.Builder setExpectedNoVarySearchData(
    @NonNull NoVarySearchHeader expectedNoVarySearchHeader
)

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
@NonNull NoVarySearchHeader expectedNoVarySearchHeader

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

Returns
@NonNull PrefetchParameters.Builder

This builder instance for chaining.

setJavaScriptEnabled

@Profile.ExperimentalUrlPrefetch
public @NonNull PrefetchParameters.Builder setJavaScriptEnabled(boolean javaScriptEnabled)

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
boolean javaScriptEnabled

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

Returns
@NonNull PrefetchParameters.Builder

This builder instance for chaining.

setVariationsId

@Profile.ExperimentalUrlPrefetch
public @NonNull PrefetchParameters.Builder setVariationsId(@Nullable Integer variationsId)

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

Parameters
@Nullable Integer variationsId

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

Returns
@NonNull PrefetchParameters.Builder

This builder instance for chaining.