Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions) Summary: [Nested Classes](https://developer.android.com/reference/android/net/http/DnsOptions#nestedclasses) \| [Constants](https://developer.android.com/reference/android/net/http/DnsOptions#constants) \| [Methods](https://developer.android.com/reference/android/net/http/DnsOptions#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/net/http/DnsOptions#inhmethods)

# DnsOptions

*** ** * ** ***


`
public

final

class
DnsOptions
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.net.http.DnsOptions |

<br />

*** ** * ** ***

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 ||
|---|---|
| ` class` | `https://developer.android.com/reference/android/net/http/DnsOptions.Builder` Builder for `https://developer.android.com/reference/android/net/http/DnsOptions`. |
| ` class` | `https://developer.android.com/reference/android/net/http/DnsOptions.StaleDnsOptions` A class configuring the stale DNS functionality. |

| ### Constants ||
|---|---|
| `int` | `https://developer.android.com/reference/android/net/http/DnsOptions#DNS_OPTION_DISABLED` Option is disabled. |
| `int` | `https://developer.android.com/reference/android/net/http/DnsOptions#DNS_OPTION_ENABLED` Option is enabled. |
| `int` | `https://developer.android.com/reference/android/net/http/DnsOptions#DNS_OPTION_UNSPECIFIED` Option is unspecified, platform default value will be used. |

| ### Public methods ||
|---|---|
| ` int` | ` https://developer.android.com/reference/android/net/http/DnsOptions#getPersistHostCache()() ` See `https://developer.android.com/reference/android/net/http/DnsOptions.Builder#setPersistHostCache(int)` |
| ` https://developer.android.com/reference/java/time/Duration` | ` https://developer.android.com/reference/android/net/http/DnsOptions#getPersistHostCachePeriod()() ` See `https://developer.android.com/reference/android/net/http/DnsOptions.Builder#setPersistHostCachePeriod(java.time.Duration)` |
| ` int` | ` https://developer.android.com/reference/android/net/http/DnsOptions#getPreestablishConnectionsToStaleDnsResults()() ` See `https://developer.android.com/reference/android/net/http/DnsOptions.Builder#setPreestablishConnectionsToStaleDnsResults(int)` |
| ` int` | ` https://developer.android.com/reference/android/net/http/DnsOptions#getStaleDns()() ` See `https://developer.android.com/reference/android/net/http/DnsOptions.Builder#setStaleDns(int)` |
| ` https://developer.android.com/reference/android/net/http/DnsOptions.StaleDnsOptions` | ` https://developer.android.com/reference/android/net/http/DnsOptions#getStaleDnsOptions()() ` See `https://developer.android.com/reference/android/net/http/DnsOptions.Builder#setStaleDnsOptions(android.net.http.DnsOptions.StaleDnsOptions)` |
| ` int` | ` https://developer.android.com/reference/android/net/http/DnsOptions#getUseHttpStackDnsResolver()() ` See `https://developer.android.com/reference/android/net/http/DnsOptions.Builder#setUseHttpStackDnsResolver(int)` |

| ### Inherited methods |
|---|---|
| From class ` https://developer.android.com/reference/java/lang/Object ` |---|---| | ` https://developer.android.com/reference/java/lang/Object` | ` https://developer.android.com/reference/java/lang/Object#clone()() ` Creates and returns a copy of this object. | | ` boolean` | ` https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj) ` Indicates whether some other object is "equal to" this one. | | ` void` | ` https://developer.android.com/reference/java/lang/Object#finalize()() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. | | ` final https://developer.android.com/reference/java/lang/Class<?>` | ` https://developer.android.com/reference/java/lang/Object#getClass()() ` Returns the runtime class of this `Object`. | | ` int` | ` https://developer.android.com/reference/java/lang/Object#hashCode()() ` Returns a hash code value for the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notify()() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#notifyAll()() ` Wakes up all threads that are waiting on this object's monitor. | | ` https://developer.android.com/reference/java/lang/String` | ` https://developer.android.com/reference/java/lang/Object#toString()() ` Returns a string representation of the object. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void` | ` https://developer.android.com/reference/java/lang/Object#wait()() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||

## Constants

### DNS_OPTION_DISABLED

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public static final int DNS_OPTION_DISABLED
```

Option is disabled.

<br />

Constant Value:

2
(0x00000002)


### DNS_OPTION_ENABLED

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public static final int DNS_OPTION_ENABLED
```

Option is enabled.

<br />

Constant Value:

1
(0x00000001)


### DNS_OPTION_UNSPECIFIED

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public static final int DNS_OPTION_UNSPECIFIED
```

Option is unspecified, platform default value will be used.

<br />

Constant Value:

0
(0x00000000)


## Public methods

### getPersistHostCache

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public int getPersistHostCache ()
```

See `https://developer.android.com/reference/android/net/http/DnsOptions.Builder#setPersistHostCache(int)`

<br />

| Returns ||
|---|---|
| `int` | Value is one of the following: - `https://developer.android.com/reference/android/net/http/DnsOptions#DNS_OPTION_UNSPECIFIED` - `https://developer.android.com/reference/android/net/http/DnsOptions#DNS_OPTION_ENABLED` - `https://developer.android.com/reference/android/net/http/DnsOptions#DNS_OPTION_DISABLED` |

### getPersistHostCachePeriod

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public Duration getPersistHostCachePeriod ()
```

See `https://developer.android.com/reference/android/net/http/DnsOptions.Builder#setPersistHostCachePeriod(java.time.Duration)`

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/java/time/Duration` | This value may be `null`. <br /> |

### getPreestablishConnectionsToStaleDnsResults

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public int getPreestablishConnectionsToStaleDnsResults ()
```

See `https://developer.android.com/reference/android/net/http/DnsOptions.Builder#setPreestablishConnectionsToStaleDnsResults(int)`

<br />

| Returns ||
|---|---|
| `int` | Value is one of the following: - `https://developer.android.com/reference/android/net/http/DnsOptions#DNS_OPTION_UNSPECIFIED` - `https://developer.android.com/reference/android/net/http/DnsOptions#DNS_OPTION_ENABLED` - `https://developer.android.com/reference/android/net/http/DnsOptions#DNS_OPTION_DISABLED` |

### getStaleDns

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public int getStaleDns ()
```

See `https://developer.android.com/reference/android/net/http/DnsOptions.Builder#setStaleDns(int)`

<br />

| Returns ||
|---|---|
| `int` | Value is one of the following: - `https://developer.android.com/reference/android/net/http/DnsOptions#DNS_OPTION_UNSPECIFIED` - `https://developer.android.com/reference/android/net/http/DnsOptions#DNS_OPTION_ENABLED` - `https://developer.android.com/reference/android/net/http/DnsOptions#DNS_OPTION_DISABLED` |

### getStaleDnsOptions

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public DnsOptions.StaleDnsOptions getStaleDnsOptions ()
```

See `https://developer.android.com/reference/android/net/http/DnsOptions.Builder#setStaleDnsOptions(android.net.http.DnsOptions.StaleDnsOptions)`

<br />

| Returns ||
|---|---|
| `https://developer.android.com/reference/android/net/http/DnsOptions.StaleDnsOptions` | This value may be `null`. <br /> |

### getUseHttpStackDnsResolver

Added in [API level 34](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Also in [S Extensions 7](https://developer.android.com/sdkExtensions)

```
public int getUseHttpStackDnsResolver ()
```

See `https://developer.android.com/reference/android/net/http/DnsOptions.Builder#setUseHttpStackDnsResolver(int)`

<br />

| Returns ||
|---|---|
| `int` | Value is one of the following: - `https://developer.android.com/reference/android/net/http/DnsOptions#DNS_OPTION_UNSPECIFIED` - `https://developer.android.com/reference/android/net/http/DnsOptions#DNS_OPTION_ENABLED` - `https://developer.android.com/reference/android/net/http/DnsOptions#DNS_OPTION_DISABLED` |