Skip to content

Commit 351d21d

Browse files
committed
hostname should be nil if host is ip address, see #2125
1 parent 2a5d6c3 commit 351d21d

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

lualib/http/httpc.lua

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -83,21 +83,26 @@ end
8383
local function connect(host, timeout)
8484
local protocol, host, port = check_protocol(host)
8585
local hostaddr = host
86-
if async_dns and host:find "^[^:]-%D$" then
87-
-- if ipv6, contains colons
88-
-- if ipv4, end with a digit
89-
local msg
90-
hostaddr, msg = dns.resolve(host)
91-
if not hostaddr then
92-
error(string.format("%s dns resolve failed msg:%s", host, msg))
86+
local hostname
87+
if host:find "^[^:]-%D$" then
88+
-- it's a hostname (not ip address), because
89+
-- ipv6 contains colons
90+
-- ipv4 end with a digit
91+
hostname = host
92+
if async_dns then
93+
local msg
94+
hostaddr, msg = dns.resolve(host)
95+
if not hostaddr then
96+
error(string.format("%s dns resolve failed msg:%s", host, msg))
97+
end
9398
end
9499
end
95100

96101
local fd = socket.connect(hostaddr, port, timeout)
97102
if not fd then
98103
error(string.format("%s connect error host:%s, port:%s, timeout:%s", protocol, host, port, timeout))
99104
end
100-
local interface = gen_interface(protocol, fd, host)
105+
local interface = gen_interface(protocol, fd, hostname)
101106
if timeout then
102107
skynet.timeout(timeout, function()
103108
if not interface.finish then

0 commit comments

Comments
 (0)