Package org.xbill.DNS
Class DohResolver
java.lang.Object
org.xbill.DNS.DohResolver
- All Implemented Interfaces:
Resolver
Proof-of-concept DNS over HTTP (DoH)
resolver. This class is not suitable for high load scenarios because of the shortcomings of
Java's built-in HTTP clients. For more control, implement your own https://cloudflare-dns.com/dns-query: max streams=250, idle timeout=400s
https://dns.google/dns-query: max streams=100, idle timeout=240s
Resolver using e.g. OkHttp.
On Java 8, it uses HTTP/1.1, which is against the recommendation of RFC 8484 to use HTTP/2 and thus slower. On Java 11 or newer, HTTP/2 is always used, but the built-in HttpClient has its own issues with connection handling.
As of 2020-09-13, the following limits of public resolvers for HTTP/2 were observed:
- Since:
- 3.0
-
Constructor Summary
ConstructorsConstructorDescriptionDohResolver(String uriTemplate) Creates a new DoH resolver that performs lookups with HTTP GET and the default timeout (5s).DohResolver(String uriTemplate, int maxConcurrentRequests, Duration idleConnectionTimeout) Creates a new DoH resolver that performs lookups with HTTP GET and the default timeout (5s). -
Method Summary
Modifier and TypeMethodDescriptionDeprecated.Gets the amount of time to wait for a response before giving up.Gets the current URI used for resolving.booleanReturnstrueif the HTTP method POST to resolve,falseif GET is used.Asynchronously sends a message using the defaultForkJoinPool.commonPool().Asynchronously sends a message.voidsetEDNS(int version, int payloadSize, int flags, List<EDNSOption> options) Sets the EDNS information on outgoing messages.voidsetExecutor(Executor executor) Deprecated.voidsetIgnoreTruncation(boolean flag) Not implemented.voidsetPort(int port) Not implemented.voidsetTCP(boolean flag) Not implemented.voidsetTimeout(Duration timeout) Sets the amount of time to wait for a response before giving up.voidsetTSIGKey(TSIG key) Specifies the TSIG key that messages will be signed withvoidsetUriTemplate(String uriTemplate) Sets the URI to use for resolving, e.g.voidsetUsePost(boolean usePost) Sets the HTTP method to use for resolving.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.xbill.DNS.Resolver
send, sendAsync, setEDNS, setEDNS, setTimeout, setTimeout
-
Constructor Details
-
DohResolver
Creates a new DoH resolver that performs lookups with HTTP GET and the default timeout (5s).- Parameters:
uriTemplate- the URI to use for resolving, e.g.https://dns.google/dns-query
-
DohResolver
Creates a new DoH resolver that performs lookups with HTTP GET and the default timeout (5s).- Parameters:
uriTemplate- the URI to use for resolving, e.g.https://dns.google/dns-querymaxConcurrentRequests- Maximum concurrent HTTP/2 streams for Java 11+ or HTTP/1.1 connections for Java 8. On Java 8 this cannot exceed the system propertyhttp.maxConnections.idleConnectionTimeout- Max. idle time for HTTP/2 connections until a request is serialized. Applies to Java 11+ only.- Since:
- 3.3
-
-
Method Details
-
setPort
public void setPort(int port) Not implemented. Specify the port insetUriTemplate(String)if required. -
setTCP
public void setTCP(boolean flag) Not implemented. -
setIgnoreTruncation
public void setIgnoreTruncation(boolean flag) Not implemented.- Specified by:
setIgnoreTruncationin interfaceResolver- Parameters:
flag- Indicates whether truncated responses should be ignored.
-
setEDNS
Sets the EDNS information on outgoing messages. -
setTSIGKey
Description copied from interface:ResolverSpecifies the TSIG key that messages will be signed with- Specified by:
setTSIGKeyin interfaceResolver- Parameters:
key- The key
-
setTimeout
Description copied from interface:ResolverSets the amount of time to wait for a response before giving up.- Specified by:
setTimeoutin interfaceResolver- Parameters:
timeout- The amount of time to wait.
-
getTimeout
Description copied from interface:ResolverGets the amount of time to wait for a response before giving up.- Specified by:
getTimeoutin interfaceResolver- See Also:
-
sendAsync
Description copied from interface:ResolverAsynchronously sends a message using the defaultForkJoinPool.commonPool().The default implementation calls the deprecated
Resolver.sendAsync(Message, ResolverListener). Implementors must override at least one of thesendAsyncmethods or a stack overflow will occur. -
sendAsync
Description copied from interface:ResolverAsynchronously sends a message.The default implementation calls the deprecated
Resolver.sendAsync(Message, ResolverListener). Implementors must override at least one of thesendAsyncmethods or a stack overflow will occur. -
isUsePost
public boolean isUsePost()Returnstrueif the HTTP method POST to resolve,falseif GET is used. -
setUsePost
public void setUsePost(boolean usePost) Sets the HTTP method to use for resolving.- Parameters:
usePost-trueto use POST,falseto use GET (the default).
-
getUriTemplate
Gets the current URI used for resolving. -
setUriTemplate
Sets the URI to use for resolving, e.g.https://dns.google/dns-query -
getExecutor
Deprecated.not applicable ifsendAsync(Message, Executor)is used.Gets the defaultExecutorfor request handling, defaults toForkJoinPool.commonPool().- Since:
- 3.3
-
setExecutor
Deprecated.Sets the defaultExecutorfor request handling.- Parameters:
executor- The newExecutor, can benull(which is equivalent toForkJoinPool.commonPool()).- Since:
- 3.3
-
toString
-
sendAsync(Message, Executor)is used.