Skip to content

Commit c632603

Browse files
committed
http/client: cqueues.dns path is no longer optional
1 parent c8b4f8d commit c632603

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

http/client.lua

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
local monotime = require "cqueues".monotime
22
local ca = require "cqueues.auxlib"
33
local cs = require "cqueues.socket"
4+
local cqueues_dns = require "cqueues.dns"
45
local cqueues_dns_record = require "cqueues.dns.record"
56
local http_tls = require "http.tls"
67
local http_util = require "http.util"
@@ -125,25 +126,23 @@ local function connect(options, timeout)
125126
local path = options.path
126127
local host = options.host
127128
if not path and not http_util.is_ip(host) then
128-
local dns_resolver = options.dns_resolver
129-
if dns_resolver then
130-
local deadline = timeout and monotime()+timeout
131-
local records = {}
132-
if family == nil or family == cs.AF_UNSPEC then
133-
dns_lookup(records, dns_resolver, host, cqueues_dns_record.AAAA, nil, timeout)
134-
dns_lookup(records, dns_resolver, host, cqueues_dns_record.A, nil, deadline and deadline-monotime())
135-
elseif family == cs.AF_INET then
136-
dns_lookup(records, dns_resolver, host, cqueues_dns_record.A, cqueues_dns_record.A, timeout)
137-
elseif family == cs.AF_INET6 then
138-
dns_lookup(records, dns_resolver, host, cqueues_dns_record.AAAA, cqueues_dns_record.AAAA, timeout)
139-
end
140-
local rec = records[1]
141-
if not rec then
142-
return nil, "The name does not resolve for the supplied parameters"
143-
end
144-
host = rec:addr()
145-
timeout = deadline and deadline-monotime()
129+
local dns_resolver = options.dns_resolver or cqueues_dns.getpool()
130+
local deadline = timeout and monotime()+timeout
131+
local records = {}
132+
if family == nil or family == cs.AF_UNSPEC then
133+
dns_lookup(records, dns_resolver, host, cqueues_dns_record.AAAA, nil, timeout)
134+
dns_lookup(records, dns_resolver, host, cqueues_dns_record.A, nil, deadline and deadline-monotime())
135+
elseif family == cs.AF_INET then
136+
dns_lookup(records, dns_resolver, host, cqueues_dns_record.A, cqueues_dns_record.A, timeout)
137+
elseif family == cs.AF_INET6 then
138+
dns_lookup(records, dns_resolver, host, cqueues_dns_record.AAAA, cqueues_dns_record.AAAA, timeout)
139+
end
140+
local rec = records[1]
141+
if not rec then
142+
return nil, "The name does not resolve for the supplied parameters"
146143
end
144+
host = rec:addr()
145+
timeout = deadline and deadline-monotime()
147146
end
148147

149148
local bind = options.bind

0 commit comments

Comments
 (0)