@@ -31,7 +31,7 @@ local default_resolver_port = 53
31
31
local _M = {
32
32
_VERSION = ' 0.1' ,
33
33
_nameservers = {},
34
- search = {}
34
+ search = { ' ' }
35
35
}
36
36
37
37
local mt = { __index = _M }
@@ -67,7 +67,7 @@ function _M.parse_nameservers(path)
67
67
68
68
ngx .log (ngx .DEBUG , ' /etc/resolv.conf:\n ' , resolv_conf )
69
69
70
- local search = {}
70
+ local search = { ' ' }
71
71
local nameservers = { search = search }
72
72
local resolver = getenv (' RESOLVER' )
73
73
local domains = match (resolv_conf , ' search%s+([^\n ]+)' )
@@ -216,18 +216,13 @@ local function lookup(dns, qname, search, options)
216
216
ngx .log (ngx .DEBUG , ' host is ip address: ' , qname )
217
217
answers = { new_answer (qname ) }
218
218
else
219
- answers , err = dns :query (qname , options )
219
+ for i = 1 , # search do
220
+ local query = qname .. ' .' .. search [i ]
221
+ ngx .log (ngx .DEBUG , ' resolver query: ' , qname , ' search: ' , search [i ], ' query: ' , query )
222
+ answers , err = dns :query (query , options )
220
223
221
- if not has_tld (qname ) and not have_addresses (answers ) then
222
- for i = 1 , # search do
223
-
224
- local query = qname .. ' .' .. search [i ]
225
- ngx .log (ngx .DEBUG , ' resolver query: ' , qname , ' search: ' , search [i ], ' query: ' , query )
226
- answers , err = dns :query (query , options )
227
-
228
- if answers and not answers .errcode and # answers > 0 then
229
- break
230
- end
224
+ if answers and not answers .errcode and # answers > 0 then
225
+ break
231
226
end
232
227
end
233
228
end
@@ -249,8 +244,7 @@ function _M.get_servers(self, qname, opts)
249
244
end
250
245
251
246
local cache = self .cache
252
- local search = self .search or {}
253
-
247
+ local search = self .search or _M .search
254
248
255
249
-- TODO: pass proper options to dns resolver (like SRV query type)
256
250
0 commit comments