All Products
Search
Document Center

HTTPDNS:Configure preferences

Last Updated:Sep 15, 2022

Configure the local logging feature for HTTPDNS

We recommend that you disable the local logging feature for HTTPDNS when you publish an app that integrates with HTTPDNS.

Operation definition

- (void)setLogEnabled:(BOOL)enable;

Parameters

Parameter

Type

Required

Description

enable

Boolean

Yes

Specifies whether to enable the local logging feature for HTTPDNS.

Specify the callback function for log output

Notice

This operation is supported only in SDK V1.6.20 or later.

Operation definition

- (void)setLogHandler:(id<HttpdnsLoggerProtocol>)logHandler;

Parameters

Parameter

Type

Required

Description

logHandler

id<HttpdnsLoggerProtocol>

Yes

The callback function for log output.

Specify the type of a domain name resolution request

Specify the type of a domain name resolution request for HTTPDNS. By default, if the request type is not specified, the HTTP request type is used.

Note

HTTP requests are processed based on the underlying CFNetwork framework, and are not affected by applicant tracking systems (ATSs).

Operation definition

- (void)setHTTPSRequestEnabled:(BOOL)enable;

Parameters

Parameter

Type

Required

Description

enable

Boolean

Yes

Valid values:

YES: HTTPS request type

NO: HTTP request type

Configure the persistent cache feature

The persistent cache feature is used to shorten the time to the first meaningful paint. The feature stores the last DNS record to the local persistence layer. After an app is restarted, the DNS record stored at the local persistence layer is preferentially used for resolution if the persistent cache feature is enabled. As a result, the IP address in an expired DNS record may be used for the first resolution. An expired DNS record is an DNS record whose time-to-live (TTL) period has elapsed. In most cases, the IP address can be used for resolution.

Note

  • If the IP addresses of servers are frequently changed, we recommend that you do not use the persistent cache feature to prevent impacts on your services. Proceed with caution when you use this feature.

  • The persistent cache feature affects only the result of the first domain name resolution. Subsequent resolution requests are sent to the HTTPDNS server, and the local cache is updated.

  • After the persistent cache feature is enabled, the DNS records are updated to the local cache. After the app is restarted, the local cache is loaded to the memory.

Operation definition

- (void)setCachedIPEnabled:(BOOL)enable;

Parameters

Parameter

Type

Required

Description

enable

Boolean

Yes

Valid values:

True: enabled

False: disabled

Perform common pre-resolution

Register domain names that you want to use for future operations with an HTTPDNS SDK. This way, the SDK can resolve the domain names in advance to reduce the latency of requests during domain name resolution.

Operation definition

- (void)setPreResolveHosts:(NSArray *)hosts;

Parameters

Parameter

Type

Required

Description

hosts

NSArray

Yes

An array that consists of the pre-resolved domain names.

Perform advanced pre-resolution

Pre-resolve domain names to IPv4 addresses and IPv6 addresses.

Note

If you want to pre-resolve domain names to IPv6 addresses, enable IPv6-based resolution before the resolution.

Operation definition

 - (void)setPreResolveHosts:(NSArray *)hosts queryIPType:(AlicloudHttpDNS_IPType)ipType;

Parameters

Parameter

Type

Required

Description

hosts

NSArray

Yes

An array that consists of the pre-resolved domain names.

ipType

AlicloudHttpDNS_IPType

Yes

Valid values:

  • AlicloudHttpDNS_IPTypeV4 (IPv4)

  • AlicloudHttpDNS_IPTypeV6 (IPv6)

  • AlicloudHttpDNS_IPTypeV64 (IPv4 + IPv6)

Allow HTTPDNS to return the IP addresses in expired DNS records of a domain name

Specify whether to allow HTTPDNS to return the IP addresses in expired DNS records of a domain name. We recommend that you set the enable parameter to YES. The default value of the enable parameter is NO.

Note

  • If the enable parameter is set to YES, the SDK returns the IP addresses in expired DNS records in real time and performs asynchronous updates to obtain the latest IP addresses.

  • Assume that the enable parameter is set to NO, the DNS record of a domain name is cached, and the TTL period of the DNS record is 60 seconds. You can call asynchronous resolution operations, such as getIpByHostAsync, within 60 seconds to obtain the cached DNS record. If you call the asynchronous resolution operations for the first time after 60 seconds, null is returned, and asynchronous domain name resolution is performed to update the cache.

Operation definition

- (void)setExpiredIPEnabled:(BOOL)enable;

Parameters

Parameter

Type

Required

Description

enable

Boolean

Yes

Specifies whether to return the IP addresses in expired DNS records of a domain name. Valid values:

YES

NO

Specify whether to enable the automatic refresh feature when the network type is changed.

Specify whether to automatically refresh the resolution results of all domain names when the network type is changed. If you enable this feature, the resolution results of all domain names are automatically refreshed when the network type is changed, but traffic is generated.

Notice

  • The network types include Wi-Fi, cellular, and no network.

  • If you switch between 4G and 3G, the network type is not changed.

  • If you replace your Subscriber Identity Module (SIM) card, the network type is not changed.

Operation definition

- (void)setPreResolveAfterNetworkChanged:(BOOL)enable;

Parameters

Parameter

Type

Required

Description

enable

Boolean

Yes

Specifies whether to automatically refresh the resolution results of all domain names when the network type is changed. Valid values:

  • YES: The resolution results of all domain names are automatically refreshed when the network type is changed.

  • NO: The SDK only deletes the cached resolution results of all domain names when the network type is changed. The domain names are resolved again only if they are requested later.

Specify a region

After you specify a region, the service IP addresses are updated by region.

Notice

  • This operation is supported only in SDK V1.18 or later.

  • If the region that you specify is the same as the previous region that you specified or a different region is repeatedly specified within 5 minutes, the service IP addresses are not updated.

Operation definition

- (void)setRegion:(NSString *)region;

Parameters

Parameter

Type

Required

Description

region

NSString

Yes

The region that you want to specify. You can specify a region outside the Chinese mainland to update the service IP addresses of the region. Valid values: hk and sg. The value hk specifies the China (Hong Kong) region, and the value sg specifies the Singapore (Singapore) region. After you specify a region, the service IP addresses in the region are updated.

The default value is hk.

Clear the cached DNS records of a domain name

If you use HTTPDNS, you can call this operation to clear the cached DNS records of domain names. This way, the resolution results can be updated within seconds. For example, the domain name is xxx.com and is resolved to the IP address ip1. If attacks occur on ip1, you can perform the following steps to migrate the traffic of ip1 to ip2:

  1. Change the IP address that corresponds to the domain name to ip2 in the HTTPDNS console. The HTTPDNS server immediately obtains the change and clears the cached DNS record that contains ip1 for the domain name.

  2. Call this operation to clear the DNS record of the domain name xxx.com from the local cache.

  3. If a request is initiated after the cache is cleared from the app, the server resends a request to the authoritative server to obtain ip2 in the latest DNS record. This way, ip2 is immediately used as the actual IP address for resolution.

Notice

  • This operation is supported only in SDK V2.0.4 or later.

  • The memory cache is synchronously cleared, and the sandbox cache is asynchronously cleared.

Operation definition

- (void)cleanHostCache:(NSArray <NSString *>*)hostArray;

Parameters

Parameter

Type

Required

Description

hostArray

NSArray <NSString *>*

Yes

An array consisting of the domain name whose DNS record you want to clear from the local cache. If you want to clear all data, set this parameter to nil or an empty array.