All Products
Search
Document Center

HTTPDNS:Configure degradation policies

Last Updated:Jan 05, 2023

Configure degradation policies

You can configure a degradation policy to change the method that is used for domain name resolution to native DNS resolution.

Important

The degradation policy specifies the domain names for which native DNS resolution is required. The SDK returns empty resolution results for these domain names. The specific degradation operation is completed by the business code after the SDK returns empty resolution results. The degradation logic is the same as the logic that is used when the SDK fails to resolve domain names. The SDK does not use the local DNS server for resolution.

Operation definition

void setDegradationFilter(DegradationFilter filter);
public interface DegradationFilter {
    /**
     * Degradation filter
     *
     * @param hostName The domain name that you want to resolve, such as www.aliyun.com. You can filter the domain names that are not resolved by HTTPDNS.
     * @return Specify whether to perform native DNS resolution.
     */
    boolean shouldDegradeHttpDNS(String hostName);
}

Parameters

Parameter

Type

Required

Description

filter

DegradationFilter

Yes

The degradation proxy.

Sample code

// httpdns specifies the service instance that is obtained after initialization.
DegradationFilter filter = new DegradationFilter() {
            @Override
            public boolean shouldDegradeHttpDNS(String hostName) {
                // You can specify custom degradation logic. In this example, www.aliyuno.com is not resolved by using HTTPDNS.
                // Refer to the HTTPDNS API documentation. If an intermediate HTTP proxy exists, use the local DNS server for resolution.
                return hostName.equals("www.aliyuno.com");
            }
        };
// Import the filter to HTTPDNS. The shouldDegradeHTTPDNS method is called during resolution to check whether HTTPDNS is used.
httpdns.setDegradationFilter(filter);

Configure a degradation filter

You can call this operation to filter the domain names that are not resolved by HTTPDNS.

Operation definition

    boolean shouldDegradeHttpDNS(String hostName);

Parameters

Parameter

Type

Required

Description

hostname

String

Yes

The domain name that you want to resolve, such as www.aliyun.com. You can filter the domain names that are not resolved by HTTPDNS.

return

Boolean

No

Specifies whether to perform native DNS resolution.

Sample code

DegradationFilter filter = new DegradationFilter() {
            @Override
            public boolean shouldDegradeHttpDNS(String hostName) {
                // You can specify custom degradation logic. In this example, www.aliyuno.com is not resolved by using HTTPDNS.
                // Refer to the HTTPDNS API documentation. If an intermediate HTTP proxy exists, use the local DNS server for resolution.
                return hostName.equals("www.aliyuno.com");
            }
        };