QuicOptions.Builder

public class QuicOptions.Builder


Builder for QuicOptions.

Summary

Public methods

QuicOptions.Builder

Adds a host to the QUIC allowlist.

QuicOptions.Builder

Adds a QUIC tag to send in a QUIC handshake's connection options that only affects the client.

QuicOptions.Builder

Adds a QUIC tag to send in a QUIC handshake's connection options.

QuicOptions.Builder

Adds a QUIC version to the list of QUIC versions to enable.

QuicOptions.Builder

Sets an arbitrary QUICHE flag.

QuicOptions

Creates and returns the final QuicOptions instance, based on the values in this builder.

QuicOptions.Builder
@QuicOptions.Experimental
closeSessionsOnIpChange(boolean closeSessionsOnIpChange)

Sets whether QUIC sessions should be closed on IP address change.

QuicOptions.Builder
@QuicOptions.Experimental
delayJobsWithAvailableSpdySession(
    boolean delayJobsWithAvailableSpdySession
)

Sets whether Cronet should wait for the primary path (usually QUIC) to be ready even if there's a secondary path of reaching the server (SPDY / HTTP2) which is ready immediately.

QuicOptions.Builder
@QuicOptions.Experimental
enableTlsZeroRtt(boolean enableTlsZeroRtt)

Sets whether TLS with 0-RTT should be enabled.

QuicOptions.Builder
@QuicOptions.Experimental
goawaySessionsOnIpChange(boolean goawaySessionsOnIpChange)

Sets whether QUIC sessions should be goaway'd on IP address change.

QuicOptions.Builder
@QuicOptions.Experimental
increaseBrokenServicePeriodExponentially(
    boolean increaseBrokenServicePeriodExponentially
)

Sets whether the broken server period should scale exponentially.

QuicOptions.Builder
@QuicOptions.Experimental
retryWithoutAltSvcOnQuicErrors(boolean retryWithoutAltSvcOnQuicErrors)

Sets whether requests that failed with a QUIC protocol errors should be retried without using any alt-svc servers.

QuicOptions.Builder
@QuicOptions.Experimental
setCryptoHandshakeTimeoutSeconds(long cryptoHandshakeTimeoutSeconds)

Sets the timeout for a connection SSL handshake.

QuicOptions.Builder
setHandshakeUserAgent(String handshakeUserAgent)

Sets the user agent to be used outside of HTTP requests (for example for QUIC handshakes).

QuicOptions.Builder

Same as setIdleConnectionTimeoutSeconds but using java.time.Duration.

QuicOptions.Builder
setIdleConnectionTimeoutSeconds(long idleConnectionTimeoutSeconds)

Sets the maximum idle time for a connection.

QuicOptions.Builder
setInMemoryServerConfigsCacheSize(int inMemoryServerConfigsCacheSize)

Sets how many server configurations (metadata like list of alt svc, whether QUIC is supported, etc.) should be held in memory.

QuicOptions.Builder
@QuicOptions.Experimental
setInitialBrokenServicePeriodSeconds(
    long initialBrokenServicePeriodSeconds
)

Sets the initial for which Cronet shouldn't attempt to use QUIC for a given server after the server's QUIC support turned out to be broken.

QuicOptions.Builder
@QuicOptions.Experimental
setPreCryptoHandshakeIdleTimeoutSeconds(
    long preCryptoHandshakeIdleTimeoutSeconds
)

Sets the maximum idle time for a connection which hasn't completed a SSL handshake yet.

QuicOptions.Builder
@QuicOptions.Experimental
setRetransmittableOnWireTimeoutMillis(
    long retransmittableOnWireTimeoutMillis
)

Sets the maximum desired time between packets on wire.

Public methods

addAllowedQuicHost

public QuicOptions.Builder addAllowedQuicHost(String quicHost)

Adds a host to the QUIC allowlist.

If no hosts are specified, the per-host allowlist functionality is disabled. Otherwise, Cronet will only use QUIC when talking to hosts on the allowlist.

Returns
QuicOptions.Builder

the builder for chaining

addClientConnectionOption

@QuicOptions.QuichePassthroughOption
public QuicOptions.Builder addClientConnectionOption(String clientConnectionOption)

Adds a QUIC tag to send in a QUIC handshake's connection options that only affects the client.

See addConnectionOption for more details.

addConnectionOption

@QuicOptions.QuichePassthroughOption
public QuicOptions.Builder addConnectionOption(String connectionOption)

Adds a QUIC tag to send in a QUIC handshake's connection options.

The QUIC tags should be presented as strings up to four letters long (for instance, NBHD).

As the QUIC tags are under active development and some are only relevant to the server, Cronet doesn't attempt to maintain a complete list of all supported QUIC flags as a part of the API. The flags. Flags supported by QUICHE, a QUIC implementation used by Cronet and Google servers, can be found here.

Returns
QuicOptions.Builder

the builder for chaining

addEnabledQuicVersion

@QuicOptions.QuichePassthroughOption
public QuicOptions.Builder addEnabledQuicVersion(String enabledQuicVersion)

Adds a QUIC version to the list of QUIC versions to enable.

If no versions are specified, Cronet will use a list of default QUIC versions.

The version format is specified by QUICHE. Outside of filtering out values known to be obsolete, Cronet doesn't process the versions anyhow and simply passes them along to QUICHE.

Returns
QuicOptions.Builder

the builder for chaining

addExtraQuicheFlag

@QuicOptions.QuichePassthroughOption
public QuicOptions.Builder addExtraQuicheFlag(String extraQuicheFlag)

Sets an arbitrary QUICHE flag. Flags should be passed in FLAG_NAME=FLAG_VALUE format. See the QUICHE code base for a full list of flags.

Returns
QuicOptions.Builder

the builder for chaining

build

public QuicOptions build()

Creates and returns the final QuicOptions instance, based on the values in this builder.

closeSessionsOnIpChange

@QuicOptions.Experimental
public QuicOptions.Builder closeSessionsOnIpChange(boolean closeSessionsOnIpChange)

Sets whether QUIC sessions should be closed on IP address change.

Don't use in combination with connection migration (configured using ConnectionMigrationOptions).

Returns
QuicOptions.Builder

the builder for chaining

delayJobsWithAvailableSpdySession

@QuicOptions.Experimental
public QuicOptions.Builder delayJobsWithAvailableSpdySession(
    boolean delayJobsWithAvailableSpdySession
)

Sets whether Cronet should wait for the primary path (usually QUIC) to be ready even if there's a secondary path of reaching the server (SPDY / HTTP2) which is ready immediately.

Returns
QuicOptions.Builder

the builder for chaining

enableTlsZeroRtt

@QuicOptions.Experimental
public QuicOptions.Builder enableTlsZeroRtt(boolean enableTlsZeroRtt)

Sets whether TLS with 0-RTT should be enabled.

0-RTT is a performance optimization avoiding an extra round trip when resuming connections to a known server.

Returns
QuicOptions.Builder

the builder for chaining

goawaySessionsOnIpChange

@QuicOptions.Experimental
public QuicOptions.Builder goawaySessionsOnIpChange(boolean goawaySessionsOnIpChange)

Sets whether QUIC sessions should be goaway'd on IP address change.

Don't use in combination with connection migration (configured using ConnectionMigrationOptions).

Returns
QuicOptions.Builder

the builder for chaining

increaseBrokenServicePeriodExponentially

@QuicOptions.Experimental
public QuicOptions.Builder increaseBrokenServicePeriodExponentially(
    boolean increaseBrokenServicePeriodExponentially
)

Sets whether the broken server period should scale exponentially.

If set to true, the initial delay (configurable by setInitialBrokenServicePeriodSeconds) will be scaled exponentially for subsequent retries (SCALING_FACTOR^NUM_TRIES * delay). If false, the delay will scale linearly (SCALING_FACTOR * NUM_TRIES * delay).

Returns
QuicOptions.Builder

the builder for chaining

retryWithoutAltSvcOnQuicErrors

@QuicOptions.Experimental
public QuicOptions.Builder retryWithoutAltSvcOnQuicErrors(boolean retryWithoutAltSvcOnQuicErrors)

Sets whether requests that failed with a QUIC protocol errors should be retried without using any alt-svc servers.

Returns
QuicOptions.Builder

the builder for chaining

setCryptoHandshakeTimeoutSeconds

@QuicOptions.Experimental
public QuicOptions.Builder setCryptoHandshakeTimeoutSeconds(long cryptoHandshakeTimeoutSeconds)

Sets the timeout for a connection SSL handshake.

Returns
QuicOptions.Builder

the builder for chaining

setHandshakeUserAgent

public QuicOptions.Builder setHandshakeUserAgent(String handshakeUserAgent)

Sets the user agent to be used outside of HTTP requests (for example for QUIC handshakes).

To set the default user agent for HTTP requests, use setUserAgent instead.

Returns
QuicOptions.Builder

the builder for chaining

setIdleConnectionTimeout

@RequiresApi(value = VERSION_CODES.O)
public QuicOptions.Builder setIdleConnectionTimeout(@NonNull Duration idleConnectionTimeout)

Same as setIdleConnectionTimeoutSeconds but using java.time.Duration.

Returns
QuicOptions.Builder

the builder for chaining

setIdleConnectionTimeoutSeconds

public QuicOptions.Builder setIdleConnectionTimeoutSeconds(long idleConnectionTimeoutSeconds)

Sets the maximum idle time for a connection. The actual value for the idle timeout is the minimum of this value and the server's and is negotiated during the handshake. Thus, it only applies after the handshake has completed. If no activity is detected on the connection for the set duration, the connection is closed.

See RFC 9114, section 5.1 for more details.

Returns
QuicOptions.Builder

the builder for chaining

setInMemoryServerConfigsCacheSize

public QuicOptions.Builder setInMemoryServerConfigsCacheSize(int inMemoryServerConfigsCacheSize)

Sets how many server configurations (metadata like list of alt svc, whether QUIC is supported, etc.) should be held in memory.

If the storage path is set (setStoragePath, Cronet will also persist the server configurations on disk.

Returns
QuicOptions.Builder

the builder for chaining

setInitialBrokenServicePeriodSeconds

@QuicOptions.Experimental
public QuicOptions.Builder setInitialBrokenServicePeriodSeconds(
    long initialBrokenServicePeriodSeconds
)

Sets the initial for which Cronet shouldn't attempt to use QUIC for a given server after the server's QUIC support turned out to be broken.

Once Cronet detects that a server advertises QUIC but doesn't actually speak it, it marks the server as broken and doesn't attempt to use QUIC when talking to the server for an amount of time. Once Cronet is past this point it will try using QUIC again. This is to balance short term (there's no point wasting resources to try QUIC if the server is broken) and long term (the breakage might have been temporary, using QUIC is generally beneficial) interests.

The delay is increased every unsuccessful consecutive retry. See increaseBrokenServicePeriodExponentially for details.

Returns
QuicOptions.Builder

the builder for chaining

setPreCryptoHandshakeIdleTimeoutSeconds

@QuicOptions.Experimental
public QuicOptions.Builder setPreCryptoHandshakeIdleTimeoutSeconds(
    long preCryptoHandshakeIdleTimeoutSeconds
)

Sets the maximum idle time for a connection which hasn't completed a SSL handshake yet.

Returns
QuicOptions.Builder

the builder for chaining

setRetransmittableOnWireTimeoutMillis

@QuicOptions.Experimental
public QuicOptions.Builder setRetransmittableOnWireTimeoutMillis(
    long retransmittableOnWireTimeoutMillis
)

Sets the maximum desired time between packets on wire.

When the retransmittable-on-wire time is exceeded Cronet will probe quality of the network using artificial traffic. Smaller timeouts will typically result in faster discovery of a broken or degrading path, but also larger usage of resources (battery, data).

Returns
QuicOptions.Builder

the builder for chaining