@@ -34,19 +34,21 @@ const protocols = {
3434} ;
3535
3636const makeRequest = ( url , query ) => new Promise ( ( resolve , reject ) => {
37- const index = url . indexOf ( '://' ) ;
38- if ( index === - 1 ) url = `https://${ url } ` ;
37+ if ( ! url . includes ( '/' ) ) { // pure IP or pure domain like "1.0.0.1" or "dns.google"
38+ url += '/dns-query' ;
39+ }
40+ if ( ! url . includes ( '://' ) ) url = `https://${ url } ` ;
3941 const u = new URL ( url ) ;
42+
4043 // The DNS query is included in a single variable named “dns” in the
4144 // query component of the request URI. The value of the “dns” variable
4245 // is the content of the DNS request message, encoded with base64url
4346 // [RFC4648](https://datatracker.ietf.org/doc/html/rfc8484#section-4.1).
44- const searchParams = u . searchParams ;
45- searchParams . set ( 'dns' , query ) ;
46- u . search = searchParams . toString ( ) ;
47+ u . searchParams . set ( 'dns' , query ) ;
48+
4749 const get = protocols [ u . protocol ] ;
4850 if ( ! get ) throw new Error ( `Unsupported protocol: ${ u . protocol } , must be specified (http://, https:// or h2://)` ) ;
49- const req = get ( u . toString ( ) , { headers : { accept : 'application/dns-message' } } , resolve ) ;
51+ const req = get ( u . href , { headers : { accept : 'application/dns-message' } } , resolve ) ;
5052 if ( req ) req . on ( 'error' , reject ) ;
5153} ) ;
5254
0 commit comments