DnsOptions


class DnsOptions
kotlin.Any
   ↳ android.net.http.DnsOptions

A class configuring the host resolution functionality. Note that while we refer to DNS as the most common mechanism being used for brevity, settings apply to other means of resolving hostnames like hosts file resolution.

Hostnames can be resolved in two ways - either by using the system resolver (using getaddrinfo provided by system libraries), or by using a custom resolver which is tailored for the HTTP networking stack.

The built-in stack provides several advantages over using the global system resolver:

  • It has been tailored to the needs of the HTTP networking stack, particularly speed and stability.
  • getaddrinfo is a blocking call which requires dedicating worker threads and makes cancellation impossible (we need to abandon the thread until the call completes)
  • The getaddrinfo interface gives no insight into the root cause of failures
  • struct addrinfo provides no TTL (Time To Live) of the returned addresses. This restricts flexibility of handling caching (e.g. allowing the use of stale DNS records) and requires us to either rely on OS DNS caches, or be extremely conservative with the TTL.

Most configuration in this class is only applicable if the built-in DNS resolver is used.

Summary

Nested classes

Builder for DnsOptions.

A class configuring the stale DNS functionality.

Constants
static Int

Option is disabled.

static Int

Option is enabled.

static Int

Option is unspecified, platform default value will be used.

Public methods
Int

See Builder#setPersistHostCache(int)

Duration?

See Builder#setPersistHostCachePeriod

Int

See Builder#setPreestablishConnectionsToStaleDnsResults(int)

Int

See Builder#setStaleDns(int)

DnsOptions.StaleDnsOptions?

See Builder#setStaleDnsOptions

Int

See Builder#setUseHttpStackDnsResolver(int)

Constants

DNS_OPTION_DISABLED

static val DNS_OPTION_DISABLED: Int

Option is disabled.

Value: 2

DNS_OPTION_ENABLED

static val DNS_OPTION_ENABLED: Int

Option is enabled.

Value: 1

DNS_OPTION_UNSPECIFIED

static val DNS_OPTION_UNSPECIFIED: Int

Option is unspecified, platform default value will be used.

Value: 0

Public methods

getPersistHostCachePeriod

fun getPersistHostCachePeriod(): Duration?

See Builder#setPersistHostCachePeriod

Return
Duration? This value may be null.

getStaleDnsOptions

fun getStaleDnsOptions(): DnsOptions.StaleDnsOptions?

See Builder#setStaleDnsOptions

Return
DnsOptions.StaleDnsOptions? This value may be null.